CF2218C.The 67th Permutation Problem

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

The 67th Permutation Problem

Upon arriving at school, Macaque was rather brusquely greeted by his friend, AG-88301, the latter having skived off his homework due to spending the entire night yapping to an unsuspecting stranger about his groundbreaking work on a proof of the Collatz conjecture and his 6767-th unreciprocated love interest. So, as had become customary, AG-88301, with ever decreasing levels of gratitude or appreciation, made Macaque do his homework for him. At this point, Macaque had had enough, and turned to his minions (you guys!) to solve AG-88301's homework task.

You are given an integer nn. You must construct a permutation^{\text{∗}} of length 3n3n such that, if you partition the permutation into nn contiguous blocks with 33 elements, the sum of the medians^{\text{†}} of these blocks is maximised.

More formally, you must construct a permutation pp of length 3n3n such that $um_{i=0}^{n-1}\operatorname{median}(a_{3i+1},a_{3i+2},a_{3i+3})$ is maximised. If there are multiple possible pp, output any.

^{\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{†}}The median of an array bb containing 33 elements is the 22-nd element after bb is sorted in non-decreasing order.

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 an integer nn (1n1051 \leq n \leq 10^5).

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

Output

For each test case, output a permutation pp such that the sum of the medians of the contiguous blocks is maximised. If there are multiple possible pp, output any.

Note

In the first test case, [1,3,4,2,5,6][1,3,4,2,5,6] is a possible answer because $\operatorname{median}(1,3,4) + \operatorname{median}(2,5,6) = 3+5 = 8$, and it can be shown that 88 is the maximal possible sum of medians.

In the second test case, [3,1,2][3,1,2] is a possible answer because the only achievable sum of medians when n=1n=1 is 22.

Samples

3
2
1
3
1 3 4 2 5 6 
3 1 2
5 2 4 8 3 9 7 1 6

在线编程 IDE

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