#ARC121C. [ARC121C] Odd Even Sort

[ARC121C] Odd Even Sort

Score : 500500 points

Problem Statement

Given is a sequence pp which is a permutation of (1,2,,N)(1,2, \ldots, N). Initially, the nn-th term of pp is pnp_{n}.

Your objective is to sort pp in ascending order in at most N2N^2 operations. In one operation, you make the following change on pp:

  • In the 11-st, 33-rd, and subsequent odd-numbered operations, you choose an odd number nn between 11 and N1N-1 (inclusive) to swap pnp_n and pn+1p_{n+1}.
  • In the 22-nd, 44-th, and subsequent even-numbered operations, you choose an even number nn between 22 and N1N-1 (inclusive) to swap pnp_n and pn+1p_{n+1}.

We can prove that the objective is always achievable under the Constraints of this problem. Find one sequence of operations that achieves the objective.

You will be given TT test cases and asked to solve each of them.

Constraints

  • All values in input are integers.
  • 1T2501 \leq T \leq 250
  • 2N5002 \leq N \leq 500
  • 1piN1 \leq p_i \leq N
  • pp is a permutation of (1,2,,N)(1,2,\ldots,N).
  • In one input file, the sum of NN does not exceed 500500.

Input

Input is given from Standard Input in the following format:

TT

case1\mathrm{case}_{1}

\vdots

caseT\mathrm{case}_{T}

Each case is in the following format:

NN

p1p_1 \cdots pNp_N

Output

For each of the TT test cases, in the order they are given, print your answer in the following format:

MM

a1a_1 \cdots aMa_M

Here, MM represents the length of your sequence of operations, and aia_i represents the integer you choose in the ii-th operation.

Your output will be considered correct if, for every test case, your sequence of operations achieves the objective.

2
5
2 1 3 5 4
2
1 2
2
1 4
0
  • Here is the description for the 11-st test case.- Choosing 11 in the 11-st operation makes p=(1,2,3,5,4)p = (1,2,3,5,4).
    • Choosing 44 in the 22-nd operation makes p=(1,2,3,4,5)p = (1,2,3,4,5).
    • Note that although (1,4)(1,4) is a valid sequence of operations, (4,1)(4, 1) is not.
  • Choosing 11 in the 11-st operation makes p=(1,2,3,5,4)p = (1,2,3,5,4).
  • Choosing 44 in the 22-nd operation makes p=(1,2,3,4,5)p = (1,2,3,4,5).
  • Note that although (1,4)(1,4) is a valid sequence of operations, (4,1)(4, 1) is not.
  • Also note that it is allowed to perform no operation, and it is not required to minimize the number of operations.