CF1844B.Permutations & Primes

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

Permutations & Primes

You are given a positive integer nn.

In this problem, the MEX\operatorname{MEX} of a collection of integers c1,c2,,ckc_1,c_2,\dots,c_k is defined as the smallest positive integer xx which does not occur in the collection cc.

The primality of an array a1,,ana_1,\dots,a_n is defined as the number of pairs (l,r)(l,r) such that 1lrn1 \le l \le r \le n and MEX(al,,ar)\operatorname{MEX}(a_l,\dots,a_r) is a prime number.

Find any permutation of 1,2,,n1,2,\dots,n with the maximum possible primality among all permutations of 1,2,,n1,2,\dots,n.

Note:

  • A prime number is a number greater than or equal to 22 that is not divisible by any positive integer except 11 and itself. For example, 2,5,132,5,13 are prime numbers, but 11 and 66 are not prime numbers.
  • A permutation of 1,2,,n1,2,\dots,n 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 (1t1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains a single integer nn (1n21051 \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, output nn integers: a permutation of 1,2,,n1,2,\dots,n that achieves the maximum possible primality.

If there are multiple solutions, print any of them.

Note

In the first test case, there are 33 pairs (l,r)(l,r) with 1lr21 \le l \le r \le 2, out of which 22 have a prime MEX(al,,ar)\operatorname{MEX}(a_l,\dots,a_r):

  • (l,r)=(1,1)(l,r) = (1,1): MEX(2)=1\operatorname{MEX}(2) = 1, which is not prime.
  • (l,r)=(1,2)(l,r) = (1,2): MEX(2,1)=3\operatorname{MEX}(2,1) = 3, which is prime.
  • (l,r)=(2,2)(l,r) = (2,2): MEX(1)=2\operatorname{MEX}(1) = 2, which is prime.

Therefore, the primality is 22.

In the second test case, MEX(1)=2\operatorname{MEX}(1) = 2 is prime, so the primality is 11.

In the third test case, the maximum possible primality is 88.

Samples

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

在线编程 IDE

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