CF2071B.Perfecto

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

Perfecto

A permutation pp of length nn^{\text{∗}} is perfect if, for each index ii (1in1 \le i \le n), it satisfies the following:

  • The sum of the first ii elements p1+p2++pip_1 + p_2 + \ldots + p_i is not a perfect square^{\text{†}}.

You would like things to be perfect. Given a positive integer nn, find a perfect permutation of length nn, or print 1-1 if none exists.

^{\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{†}}A perfect square is an integer that is the square of an integer, e.g., 9=329=3^2 is a perfect square, but 88 and 1414 are not.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first and only line of each test case contains a single integer nn (1n51051 \le n \le 5 \cdot 10^5).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

Output

For each test case:

  • If no solution exists, print a single integer 1-1.
  • Otherwise, print nn integers p1,p2,,pnp_1,p_2,\ldots,p_n — the perfect permutation you find.

If there are multiple solutions, print any of them.

Note

In the first test case, there is only one permutation with length n=1n = 1 that is p=[1]p = [1], which is not perfect:

  • p1=1=x2p_1 = 1 = x^2 for x=1x = 1.

In the second test case, one possible perfect permutation with length n=4n = 4 is p=[2,4,1,3]p = [2, 4, 1, 3]:

  • p1=2x2p_1 = 2 \neq x^2;
  • p1+p2=2+4=6x2p_1 + p_2 = 2 + 4 = 6 \neq x^2;
  • p1+p2+p3=2+4+1=7x2p_1 + p_2 + p_3 = 2 + 4 + 1 = 7 \neq x^2;
  • $p_1 + p_2 + p_3 + p_4 = 2 + 4 + 1 + 3 = 10 \neq x^2$.

In the third test case, one possible perfect permutation with length n=5n = 5 is p=[5,1,4,3,2]p = [5, 1, 4, 3, 2]:

  • p1=5x2p_1 = 5 \neq x^2;
  • p1+p2=5+1=6x2p_1 + p_2 = 5 + 1 = 6 \neq x^2;
  • p1+p2+p3=5+1+4=10x2p_1 + p_2 + p_3 = 5 + 1 + 4 = 10 \neq x^2;
  • $p_1 + p_2 + p_3 + p_4 = 5 + 1 + 4 + 3 = 13 \neq x^2$;
  • $p_1 + p_2 + p_3 + p_4 + p_5 = 5 + 1 + 4 + 3 + 2 = 15 \neq x^2$.

Samples

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

在线编程 IDE

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