CF2084A.Max and Mod

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

Max and Mod

You are given an integer nn. Find any permutation pp of length nn∗^{\text{∗}} such that:

  • For all 2≤i≤n2 \le i \le n, max⁡(pi−1,pi) mod i\max(p_{i - 1}, p_i) \bmod i †^{\text{†}} =i−1= i - 1 is satisfied.

If it is impossible to find such a permutation pp, output −1-1.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

†^{\text{†}}x mod yx \bmod y denotes the remainder from dividing xx by yy.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤991 \le t \le 99). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002 \le n \le 100).

Output

For each test case:

  • If such a permutation pp doesn't exist, output a single integer −1-1.
  • Otherwise, output nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n — the permutation pp you've found. If there are multiple answers, output any of them.

Note

In the first test case, it is impossible to find such a permutation pp, so you should output −1-1.

In the fourth test case, p=[1,5,2,3,4]p = [1, 5, 2, 3, 4] satisfies the condition:

  • For i=2i = 2, max⁡(p1,p2)=5\max(p_1, p_2) = 5 and 5 mod 2=15 \bmod 2 = 1.
  • For i=3i = 3, max⁡(p2,p3)=5\max(p_2, p_3) = 5 and 5 mod 3=25 \bmod 3 = 2.
  • For i=4i = 4, max⁡(p3,p4)=3\max(p_3, p_4) = 3 and 3 mod 4=33 \bmod 4 = 3.
  • For i=5i = 5, max⁡(p4,p5)=4\max(p_4, p_5) = 4 and 4 mod 5=44 \bmod 5 = 4.

Samples

4
2
3
4
5
-1
3 2 1
-1
1 5 2 3 4

在线编程 IDE

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