Permutation Xority

 You are given an integer 

N. Construct a permutation A of length N which is attractive.

A permutation is called attractive if the bitwise XOR of all absolute differences of adjacent pairs of elements is equal to 0.

Formally, a permutation A=[A1,A2,,AN] of length N is said to be attractive if:

|A1A2||A2A3||AN1AN|=0

where  denotes the bitwise XOR operation.

Output any attractive permutation of length N. If no attractive permutation exists, print 1 instead.

Note: A permutation of length N is an array A=[A1,A2,,AN] such that every integer from 1 to N occurs exactly once in A. For example, [1,2,3] and [2,3,1] are permutations of length 3, but [1,2,1][4,1,2], and [2,3,1,4] are not.

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of a single line of input, containing one integer N.

Output Format

For each test case, output on a single line an attractive permutation of N integers, or 1 if no attractive permutation exists.

Constraints

  • 1T1000
  • 2N105
  • Sum of N over all cases won't exceed 2105.

Sample Input 1 

2
3
6

Sample Output 1 

3 2 1
5 2 3 6 4 1 

Explanation

Test Case 1: |32||21|=11=0

Note that there are other correct answers — for example, [1,2,3] would also be accepted as correct.

Test Case 2: 

Previous
Next Post »