On a desolate island lives a herd of pocket monsters in which each species has
exactly two monsters. Each monster digs a cave to live in and the caves distribute in a
row, as shown in Fig 1.
To test the IQ of the visited monster trainer, monsters propose a puzzle for the
trainer. Initially, the monsters randomly live in the caves. The mission for the trainer
is to relocate the monsters by swapping the neighboring monsters to achieve the goal
that each monster lives neighbor to the same species, as shown in Fig 2. What is the
least number of swaps to achieve the goal?
The first line has an integer t to indicate the number of test cases. In the
following, each test case consists of two integral lines: the first line consists of an
integer n, 2<=n<=15, which indicates the number of species; the second line consists
of 2n integers, separated by blanks, to represent the species of the monsters in a row.
Species are labeled from 1 to n.
For each test case, output one integer m in a line, where m is the minimum
number of swaps to achieve the goal.