CF2188A.Divisible Permutation

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

Divisible Permutation

You are given an integer nn. Construct a permutation^{\text{∗}} pp of length nn satisfying the following condition:

  • pipi+1\lvert p_i - p_{i+1} \rvert is divisible by ii for every 1in11 \le i \le n-1.

It can be proven that such a permutation always exists under the constraints of the problem.

^{\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).

Input

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

The only line of each test case contains a single integer nn (2n1002 \le n \le 100) — the length of the permutation pp to be constructed.

Output

For each test case, output nn integers p1,p2,,pnp_1,p_2,\ldots,p_n (1pin1 \le p_i \le n, all pip_i-s are distinct) — the permutation you constructed.

If there are multiple valid permutations, you may output any of them.

Note

In the first test case, p=[1,2]p=[1,2] satisfies the condition because p1p2=12=1\lvert p_1-p_2\rvert=\lvert 1-2\rvert=1, which is divisible by 11.

In the second test case, p=[2,3,1]p=[2,3,1] satisfies the condition because:

  • p1p2=23=1\lvert p_1-p_2\rvert=\lvert 2-3\rvert=1, which is divisible by 11, and
  • p2p3=31=2\lvert p_2-p_3\rvert=\lvert 3-1\rvert=2, which is divisible by 22.

Samples

2
2
3
1 2
2 3 1

在线编程 IDE

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