CF2117B.Shrink

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

Shrink

A shrink operation on an array aa of size mm is defined as follows:

  • Choose an index ii (2im12 \le i \le m - 1) such that ai>ai1a_i \gt a_{i - 1} and ai>ai+1a_i \gt a_{i + 1}.
  • Remove aia_i from the array.

Define the score of a permutation^{\text{∗}} pp as the maximum number of times that you can perform the shrink operation on pp.

Yousef has given you a single integer nn. Construct a permutation pp of length nn with the maximum possible score. If there are multiple answers, you can output any of them.

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

The first line of the input contains an integer tt (1t1031 \le t \le 10^3) — the number of test cases.

Each test case contains an integer nn (3n21053 \le n \le 2 \cdot 10^5) — the size of the permutation.

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

Output

For each test case, output any permutation p1,p2,,pnp_1, p_2, \dots, p_n that maximizes the number of shrink operations.

Note

In the first test case:

  • We choose p=[1,3,2]p = [1, 3, 2].
  • Choose index 22, and remove p2p_2 from the array. The array becomes p=[1,2]p = [1, 2].

It can be shown that the maximum number of operations we can perform is 11. Another valid answer is p=[2,3,1]p = [2, 3, 1].

In the second test case:

  • We choose p=[2,3,6,4,5,1]p = [2, 3, 6, 4, 5, 1].
  • Choose index 55, and remove p5p_5 from the array. The array becomes p=[2,3,6,4,1]p = [2, 3, 6, 4, 1].
  • Choose index 33, and remove p3p_3 from the array. The array becomes p=[2,3,4,1]p = [2, 3, 4, 1].
  • Choose index 33, and remove p3p_3 from the array. The array becomes p=[2,3,1]p = [2, 3, 1].
  • Choose index 22, and remove p2p_2 from the array. The array becomes p=[2,1]p = [2, 1].

The maximum number of operations we can perform is 44. Any permutation with a score of 44 is valid.

Samples

2
3
6
1 3 2
2 3 6 4 5 1

在线编程 IDE

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