CF1741B.Funny Permutation

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Funny Permutation

A sequence of nn numbers is called permutation if it contains all numbers from 11 to nn exactly once. For example, the sequences [3,1,4,2][3, 1, 4, 2], [11] and [2,1][2,1] are permutations, but [1,2,1][1,2,1], [0,1][0,1] and [1,3,4][1,3,4] are not.

For a given number nn you need to make a permutation pp such that two requirements are satisfied at the same time:

  • For each element pip_i, at least one of its neighbors has a value that differs from the value of pip_i by one. That is, for each element pip_i (1in1 \le i \le n), at least one of its neighboring elements (standing to the left or right of pip_i) must be pi+1p_i + 1, or pi1p_i - 1.
  • the permutation must have no fixed points. That is, for every ii (1in1 \le i \le n), piip_i \neq i must be satisfied.

Let's call the permutation that satisfies these requirements funny.

For example, let n=4n = 4. Then [4,3,1,24, 3, 1, 2] is a funny permutation, since:

  • to the right of p1=4p_1=4 is p2=p11=41=3p_2=p_1-1=4-1=3;
  • to the left of p2=3p_2=3 is p1=p2+1=3+1=4p_1=p_2+1=3+1=4;
  • to the right of p3=1p_3=1 is p4=p3+1=1+1=2p_4=p_3+1=1+1=2;
  • to the left of p4=2p_4=2 is p3=p41=21=1p_3=p_4-1=2-1=1.
  • for all ii is piip_i \ne i.

For a given positive integer nn, output any funny permutation of length nn, or output -1 if funny permutation of length nn does not exist.

Input

The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The description of the test cases follows.

Each test case consists of f single line containing one integer nn (2n21052 \le n \le 2 \cdot 10^5).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, print on a separate line:

  • any funny permutation pp of length nn;
  • or the number -1 if the permutation you are looking for does not exist.

Note

The first test case is explained in the problem statement.

In the second test case, it is not possible to make the required permutation: permutations [1,2,3][1, 2, 3], [1,3,2][1, 3, 2], [2,1,3][2, 1, 3], [3,2,1][3, 2, 1] have fixed points, and in [2,3,1][2, 3, 1] and [3,1,2][3, 1, 2] the first condition is met not for all positions.

Samples

5
4
3
7
5
2
3 4 2 1
-1
6 7 4 5 3 2 1
5 4 1 2 3
2 1

在线编程 IDE

建议全屏模式获得最佳体验