题目描述
Chef has received a challenge for which he needs your help.
Given N, find a permutation P of numbers $(1, 2, \ldots, N)$ such that:
$P_{i} \oplus P_{i+1} \neq P_{i+2} \text{$ , where } (1 ≤ i ≤ $N-2). Here \oplus$ denotes the [bitwise XOR] operation.
If multiple such permutations exist, print any. If no such permutation exists, print -1.
Note that, a permutation of length N is a sequence of $N integers P = (P_{1}, P_{2}, \ldots, P_{N})$ such that every integer from 1 to N (inclusive) appears in it exactly once. For example, (2,5,4,1,3) is a permutation of length 5 while (2, 5, 2, 1, 3) is not.
------ Input Format ------
- First line will contain T, number of test cases. Then the test cases follow.
- Each test case contains of a single integer as input, N - the length of the required permutation.
------ Output Format ------
For each test case, output in a new line, N space-separated integers, denoting a permutation satisfying the condition.
If multiple such permutations exist, print any. If no such permutation exists, print -1.
------ Constraints ------
$1 ≤ T ≤ 500$
$3 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
3
5
10
22
----- Sample Output 1 ------
-1
5 1 2 4 3
1 2 4 3 6 10 8 9 7 5
10 9 8 7 6 5 1 2 4 3 11 12 13 14 15 16 17 18 19 20 21 22
----- explanation 1 ------
Test Case $1$: There is no permutation that satisfies the given XOR condition.
Test Case $2$: $(5 \oplus 1 = 4) \text{ , } (1 \oplus 2 = 3) \text{ , } (2 \oplus 4 = 6)$
Since all the adjacent XORs are different from the next term, hence, this is a valid answer.
Test Case $3$: $(1 \oplus 2 = 3) \text{ , } (2 \oplus 4 = 6) \text{ , } (4 \oplus 3 = 7) \text{ and so on... }$
Since all the adjacent XORs are different from the next term, hence, this is a valid answer.
Test Case $4$: $(10 \oplus 9 = 3) \text{ , } (9 \oplus 8 = 1) \text{ , } (8 \oplus 7 = 15) \text{ and so on... }$
Since all the adjacent XORs are different from the next term, hence, this is a valid answer.
输入格式
见题面
输出格式
见题面