Read problem statements in [Vietnamese],
[Bengali], [Mandarin Chinese], and [Russian] as well. 

Find $K$ distinct numbers in the range $[1, N]$ such that the bitwise XOR of all the numbers is maximized. Print any set of these numbers that maximize the XOR.

------ Input ------

The first line contains an integer $T$, the number of test cases. Then the test cases follow. 
Each test case contains a single line of input, two integers $N$, $K$. 

------ Output ------
For each test case, output $K$ distinct integers in any order as described in the problem.

------ Constraints  ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ K ≤ N ≤ 10^{6}$
The sum of $N$ over all queries is at most $4\cdot 10^{6}$.
The sum of $K$ over all queries is at most $2\cdot 10^{6}$.

------ Subtasks ------
Subtask #1 (5 points):
$1 ≤ T ≤ 50$
$1 ≤ K ≤ N ≤ 20$

Subtask #2 (20 points):
$1 ≤ T ≤ 50$
$1 ≤ K ≤ N ≤ 200$
The sum of $N$ over all queries is at most $800$.
The sum of $K$ over all queries is at most $400$.

Subtask #3 (75 points): original constraints

------ Sample Input ------

3
10 1
9 2
8 7

------ Sample Output ------

10
7 8
1 2 3 4 5 6 8

------ Explanation ------
Test Case $1$: The only possible set is $\{10\}$ which gives the value $10$.

Test Case $2$: The other possible set is $\{9, 6\}$ which gives the value $9 \oplus 6 = 15 = 7 \oplus 8$.

Test Case $3$: The only possible set is $\{1, 2, 3, 4, 5, 6, 8\}$ which gives the value $1 \oplus 2 \oplus 3 \oplus 4 \oplus 5 \oplus 6 \oplus 8 = 15$.

Source: codechef | Difficulty: VERY_HARD
Tags: Bit manipulation

Mathematics

Ad-hoc


Solutions:
from math import log
precalc = [[()], [(), (1,)], [(), (2,), (1, 2)], [(), (3,), (1, 2), (1, 2, 3)], [(), (4,), (3, 4), (1, 2, 4), (1, 2, 3, 4)], [(), (5,), (3, 4), (1, 3, 5), (1, 2, 3, 5), (1, 2, 3, 4, 5)], [(), (6,), (3, 4), (4, 5, 6), (1, 4, 5, 6), (2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6)], [(), (7,), (3, 4), (4, 5, 6), (3, 5, 6, 7), (2, 3, 4, 5, 7), (1, 2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6, 7)], [(), (8,), (7, 8), (3, 4, 8), (4, 5, 6, 8), (3, 5, 6, 7, 8), (2, 3, 4, 5, 7, 8), (1, 2, 3, 4, 5, 6, 8), (1, 2, 3, 4, 5, 6, 7, 8)], [(), (9,), (7, 8), (3, 5, 9), (4, 5, 7, 9), (3, 5, 6, 7, 8), (2, 3, 4, 5, 7, 8), (1, 2, 3, 4, 5, 7, 9), (1, 2, 3, 4, 5, 6, 7, 9), (1, 2, 3, 4, 5, 6, 7, 8, 9)], [(), (10,), (7, 8), (3, 6, 10), (4, 8, 9, 10), (3, 7, 8, 9, 10), (5, 6, 7, 8, 9, 10), (3, 4, 5, 6, 8, 9, 10), (2, 3, 4, 6, 7, 8, 9, 10), (1, 2, 3, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)], [(), (11,), (7, 8), (3, 7, 11), (7, 9, 10, 11), (3, 7, 8, 9, 10), (5, 6, 7, 8, 9, 10), (3, 5, 6, 7, 9, 10, 11), (2, 3, 5, 6, 7, 8, 9, 11), (1, 2, 3, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)], [(), (12,), (7, 8), (9, 10, 12), (7, 9, 10, 11), (6, 7, 9, 11, 12), (5, 6, 7, 8, 9, 10), (5, 6, 8, 9, 10, 11, 12), (2, 6, 7, 8, 9, 10, 11, 12), (2, 3, 5, 7, 8, 9, 10, 11, 12), (3, 4, 5, 6, 7, 8, 9, 10, 11, 12), (1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)], [(), (13,), (7, 8), (9, 11, 13), (7, 9, 12, 13), (6, 7, 9, 11, 12), (7, 8, 10, 11, 12, 13), (5, 7, 8, 9, 10, 11, 13), (5, 6, 7, 8, 9, 11, 12, 13), (3, 5, 6, 7, 8, 10, 11, 12, 13), (3, 4, 5, 6, 7, 8, 9, 10, 11, 12), (1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)], [(), (14,), (7, 8), (12, 13, 14), (7, 11, 13, 14), (6, 7, 9, 11, 12), (7, 8, 10, 11, 12, 13), (8, 9, 10, 11, 12, 13, 14), (5, 6, 7, 9, 10, 11, 13, 14), (3, 5, 6, 7, 8, 10, 11, 12, 13), (3, 5, 6, 8, 9, 10, 11, 12, 13, 14), (4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), (1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)], [(), (15,), (7, 8), (12, 13, 14), (7, 11, 13, 14), (10, 11, 12, 13, 15), (7, 8, 12, 13, 14, 15), (8, 9, 10, 11, 12, 13, 14), (7, 9, 10, 11, 12, 13, 14, 15), (6, 7, 8, 9, 10, 11, 12, 13, 15), (5, 6, 7, 8, 9, 10, 12, 13, 14, 15), (4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)], [(), (16,), (15, 16), (7, 8, 16), (12, 13, 14, 16), (7, 11, 13, 14, 16), (10, 11, 12, 13, 15, 16), (7, 8, 12, 13, 14, 15, 16), (8, 9, 10, 11, 12, 13, 14, 16), (7, 9, 10, 11, 12, 13, 14, 15, 16), (6, 7, 8, 9, 10, 11, 12, 13, 15, 16), (5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16), (4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16), (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)], [(), (17,), (15, 16), (7, 9, 17), (12, 13, 15, 17), (7, 11, 13, 15, 17), (10, 11, 12, 13, 15, 16), (7, 9, 12, 13, 14, 15, 17), (8, 9, 10, 11, 12, 13, 15, 17), (7, 9, 10, 11, 12, 13, 14, 15, 16), (6, 7, 8, 9, 10, 11, 12, 13, 15, 16), (5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17), (4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17), (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)], [(), (18,), (15, 16), (7, 10, 18), (12, 16, 17, 18), (7, 11, 16, 17, 18), (13, 14, 15, 16, 17, 18), (7, 10, 14, 15, 16, 17, 18), (10, 11, 12, 14, 15, 16, 17, 18), (7, 11, 12, 13, 14, 15, 16, 17, 18), (8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18), (6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), (4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)], [(), (19,), (15, 16), (7, 11, 19), (15, 17, 18, 19), (7, 11, 16, 17, 18), (13, 14, 15, 16, 17, 18), (7, 11, 14, 15, 16, 17, 19), (10, 11, 13, 14, 15, 16, 17, 19), (7, 11, 12, 13, 14, 15, 16, 17, 18), (8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19), (6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), (4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19), (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)], [(), (20,), (15, 16), (7, 12, 20), (15, 17, 18, 19), (7, 15, 17, 18, 20), (13, 14, 15, 16, 17, 18), (7, 12, 16, 17, 18, 19, 20), (10, 14, 15, 16, 17, 18, 19, 20), (7, 13, 14, 15, 16, 17, 18, 19, 20), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (7, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20), (8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20), (7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20), (6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20), (4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20), (3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)], [(), (21,), (15, 16), (7, 13, 21), (15, 17, 20, 21), (7, 15, 17, 19, 21), (15, 16, 18, 19, 20, 21), (7, 13, 16, 17, 18, 19, 21), (13, 14, 15, 16, 17, 19, 20, 21), (7, 13, 14, 15, 16, 17, 18, 19, 20), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (7, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21), (8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21), (7, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21), (6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21), (4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21), (3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), (1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)], [(), (22,), (15, 16), (7, 14, 22), (15, 19, 21, 22), (7, 15, 20, 21, 22), (15, 16, 18, 19, 20, 21), (7, 14, 18, 19, 20, 21, 22), (13, 14, 15, 17, 18, 19, 21, 22), (7, 15, 16, 17, 18, 19, 20, 21, 22), (11, 13, 14, 16, 17, 18, 19, 20, 21, 22), (7, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22), (8, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (7, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22), (6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)], [(), (23,), (15, 16), (7, 15, 23), (15, 19, 21, 22), (7, 15, 20, 21, 22), (15, 16, 20, 21, 22, 23), (7, 15, 18, 19, 20, 21, 23), (15, 17, 18, 19, 20, 21, 22, 23), (7, 15, 16, 17, 18, 19, 20, 21, 22), (13, 14, 15, 16, 17, 18, 20, 21, 22, 23), (7, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23), (11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23), (7, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23), (6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23), (4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23), (2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23), (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23)], [(), (24,), (15, 16), (19, 20, 24), (15, 19, 21, 22), (19, 21, 22, 23, 24), (15, 16, 20, 21, 22, 23), (17, 18, 19, 20, 21, 22, 24), (15, 17, 18, 19, 20, 21, 22, 23), (14, 15, 17, 18, 19, 20, 21, 23, 24), (13, 14, 15, 16, 17, 18, 20, 21, 22, 23), (12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 24), (11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23), (11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), (9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24), (6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (6, 7, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24), (4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24)], [(), (25,), (15, 16), (19, 21, 25), (15, 19, 21, 22), (19, 21, 22, 23, 24), (15, 19, 21, 23, 24, 25), (17, 18, 19, 20, 21, 23, 25), (15, 17, 20, 21, 22, 23, 24, 25), (14, 15, 17, 18, 19, 20, 21, 23, 24), (15, 16, 18, 19, 20, 21, 22, 23, 24, 25), (12, 13, 14, 15, 17, 18, 19, 20, 21, 23, 25), (13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25), (11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25), (9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25), (7, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25), (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25), (4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25), (3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), (1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)], [(), (26,), (15, 16), (19, 22, 26), (15, 19, 25, 26), (19, 23, 24, 25, 26), (15, 19, 22, 23, 24, 26), (19, 20, 21, 22, 24, 25, 26), (15, 19, 20, 21, 22, 23, 25, 26), (17, 18, 19, 21, 22, 23, 24, 25, 26), (15, 16, 18, 19, 20, 21, 22, 23, 24, 25), (14, 15, 17, 18, 19, 20, 22, 23, 24, 25, 26), (13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26), (12, 13, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25), (11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26), (9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (7, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (4, 5, 6, 7, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26)], [(), (27,), (15, 16), (19, 23, 27), (15, 19, 25, 26), (19, 23, 24, 25, 26), (15, 19, 22, 23, 25, 27), (19, 21, 22, 23, 25, 26, 27), (15, 19, 21, 22, 24, 25, 26, 27), (17, 18, 19, 21, 22, 23, 24, 25, 26), (15, 16, 20, 21, 22, 23, 24, 25, 26, 27), (14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 27), (15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), (12, 13, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26), (13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27), (11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27), (11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27), (9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27), (7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27), (5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27), (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27), (2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27), (1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)], [(), (28,), (15, 16), (25, 26, 28), (15, 23, 27, 28), (22, 23, 25, 27, 28), (15, 23, 24, 25, 26, 28), (21, 22, 24, 25, 26, 27, 28), (15, 21, 22, 23, 25, 26, 27, 28), (18, 19, 21, 23, 24, 25, 26, 27, 28), (15, 18, 19, 21, 22, 23, 24, 26, 27, 28), (17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28), (15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), (14, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27), (13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28), (10, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28), (9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (7, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (2, 3, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)], [(), (29,), (15, 16), (25, 27, 29), (15, 23, 27, 28), (22, 23, 25, 27, 28), (15, 23, 24, 25, 27, 29), (21, 23, 24, 25, 26, 27, 29), (15, 21, 22, 23, 25, 26, 27, 28), (19, 21, 22, 23, 24, 26, 27, 28, 29), (15, 19, 21, 23, 24, 25, 26, 27, 28, 29), (17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (15, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29), (14, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29), (13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29), (11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29), (11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29), (9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29), (7, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29), (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29), (5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29), (3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29), (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28), (1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29)]]
longest = [i for i in range(1, 1000001)]

def Total(N):
	i = 0
	for j in range(1, N + 1):
		i ^= j
	return i

def getall(arr):
	i = 0
	for j in arr:
		i ^= j
	return i

def find1(actual, N, xorlargest):
	if N + 1 & N + 2 == 0:
		return longest[3:N] + [1]
	else:
		left = Total(N)
		if left == 1:
			return [i for i in longest[:N] if i not in [actual + 1, actual - 1]]
		elif left == 0:
			return [i for i in longest[:N] if i not in [actual, actual - 1]]
		else:
			right = xorlargest ^ left
			if right % 2 == 0:
				return [i for i in longest[1:N] if i not in [right + 1]]
			else:
				return [i for i in longest[1:N] if i not in [right - 1]]

def find2(actual, K):
	if K >= actual - 2:
		return longest[3:actual - 3] + [2, 3] + [actual, actual - 1] + longest[actual + 1:K + 3]
	else:
		return [actual, actual - 1] + longest[3:K + 1]

def find3(actual, K):
	if K >= actual - 3:
		return longest[3:actual - 3] + longest[actual + 1:K + 2] + [actual, actual - 2, 1] + [2, 3]
	else:
		return longest[3:K] + [actual, actual - 2, 1]

def find4(actual, K):
	if K >= actual - 5:
		temp = longest[3:actual - 5] + [actual, actual - 4, 1, 2]
		return temp if len(temp) == K else longest[3:actual - 5] + [actual, actual - 4, 1, 2] + longest[actual + 1:K + 3] + [actual - 2, actual - 1]
	else:
		return longest[3:K - 1] + [actual, actual - 4, 1, 2]

def find5(actual, K):
	if K >= actual - 2:
		return longest[3:actual - 3] + longest[actual + 1:K + 2] + [actual, actual - 1, 1, 2, 3]
	else:
		return longest[3:K - 2] + [actual, actual - 1, 1, 2, 3]
T = int(input())
twofif = 0
for test in range(T):
	(N, K) = list(map(int, input().split()))
	actual = 2 ** (len(bin(N)) - 2) // 2
	if N <= 8:
		print(' '.join(list(map(str, precalc[N][K]))))
		continue
	elif K == N:
		print(' '.join(list(map(str, [i for i in range(1, N + 1)]))))
		continue
	elif K == N - 2:
		print(' '.join(list(map(str, find1(actual, N, 2 ** (int(log(N, 2)) + 1) - 1)))))
		if len(find1(actual, N, 2 ** (int(log(N, 2)) + 1) - 1)) != K:
			foulplay()
		continue
	elif K == N - 1:
		xorTill = Total(N)
		lost = 1
		large = 0
		for i in range(1, N + 1):
			if xorTill ^ i > large:
				lost = i
				large = xorTill ^ i
		if len([i for i in longest[:N] if i not in [lost]]) != K:
			foulplay()
		print(' '.join(list(map(str, [i for i in longest[:N] if i not in [lost]]))))
		continue
	elif K == 1:
		print(N)
		continue
	elif K % 4 == 2:
		arr = find2(actual, K)
		print(' '.join(list(map(str, arr))))
	elif K % 4 == 3:
		arr = find3(actual, K)
		print(' '.join(list(map(str, arr))))
	elif K % 4 == 0:
		arr = find4(actual, K)
		print(' '.join(list(map(str, arr))))
	elif K % 4 == 1:
		arr = find5(actual, K)
		print(' '.join(list(map(str, arr))))


import math

def AllXor(N):
	if N % 4 == 1:
		return 1
	elif N % 4 == 2:
		return N + 1
	elif N % 4 == 3:
		return 0
	else:
		return N

def find(N):
	e = int(math.log(N, 2))
	return 2 ** (e + 1) - 1

def Less1(N):
	k = AllXor(N)
	maxi = -1
	removal = 1
	for i in range(1, N + 1):
		if k ^ i > maxi:
			maxi = k ^ i
			removal = i
	p = [i for i in range(1, N + 1)]
	p.remove(removal)
	print(*set(p))

def Less2(N):
	if N + 2 & N + 1 == 0:
		p = [1] + [i for i in range(4, N + 1)]
		print(*set(p))
	else:
		k = AllXor(N)
		val = find(N)
		if k == 0:
			x = 2 ** (len(bin(N)) - 2) // 2
			p = [i for i in range(1, N + 1)]
			p.remove(x)
			p.remove(x - 1)
		elif k == 1:
			x = 2 ** (len(bin(N)) - 2) // 2
			p = [i for i in range(1, N + 1)]
			p.remove(x - 1)
			p.remove(x + 1)
		else:
			t = val ^ k
			if t % 2 == 0:
				p = [i for i in range(2, N + 1)]
				p.remove(t + 1)
			else:
				p = [i for i in range(2, N + 1)]
				p.remove(t - 1)
		print(*set(p))
dp = [[0], [0, (1,)], [0, (2,), (1, 2)], [0, (3,), (1, 2), (1, 2, 3)], [0, (4,), (3, 4), (1, 2, 4), (1, 2, 3, 4)], [0, (5,), (2, 5), (1, 2, 4), (1, 2, 3, 5), (1, 2, 3, 4, 5)], [0, (6,), (1, 6), (1, 2, 4), (1, 2, 3, 6), (2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6)], [0, (7,), (1, 6), (1, 2, 4), (1, 2, 3, 7), (1, 2, 5, 6, 7), (1, 2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6, 7)], [0, (8,), (7, 8), (1, 6, 8), (1, 2, 4, 8), (1, 2, 3, 7, 8), (1, 2, 5, 6, 7, 8), (1, 2, 3, 4, 5, 6, 8), (1, 2, 3, 4, 5, 6, 7, 8)]]
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N <= 8:
		print(*set(dp[N][K]))
	elif K == 1:
		print(*set([N]))
	elif K == N:
		print(*set([i for i in range(1, N + 1)]))
	elif K == N - 1:
		Less1(N)
	elif K == N - 2:
		Less2(N)
	elif K % 4 == 2:
		x = 2 ** (len(bin(N)) - 2) // 2
		if K < x - 2:
			two = [x, x - 1] + [i for i in range(4, K + 2)]
		else:
			two = [x, x - 1] + [i for i in range(4, x - 2)] + [2, 3] + [i for i in range(x + 2, K + 4)]
		print(*two)
	elif K % 4 == 3:
		x = 2 ** (len(bin(N)) - 2) // 2
		if K < x - 3:
			three = [x, x - 2, 1] + [i for i in range(4, K + 1)]
		else:
			three = [x, x - 2, 1] + [i for i in range(4, x - 2)] + [2, 3] + [i for i in range(x + 2, K + 3)]
		print(*set(three))
	elif K % 4 == 0:
		x = 2 ** (len(bin(N)) - 2) // 2
		if K < x - 5:
			four = [x, x - 4, 1, 2] + [i for i in range(4, K)]
		else:
			four = [x, x - 4, 1, 2] + [i for i in range(4, x - 4)]
			if K > len(four):
				four += [x - 2, x - 1] + [i for i in range(x + 2, K + 4)]
		print(*set(four))
	elif K % 4 == 1:
		x = 2 ** (len(bin(N)) - 2) // 2
		if K < x - 2:
			five = [x, x - 1, 1, 2, 3] + [i for i in range(4, K - 1)]
		else:
			five = [x, x - 1, 1, 2, 3] + [i for i in range(4, x - 2)] + [i for i in range(x + 2, K + 3)]
		print(*set(five))


from math import log2

def opt_xor(N, K):
	if log2(N + 1).is_integer() and K == N - 2:
		l = 2 ** int(log2(N))
		return [*range(1, l - 1), *range(l + 1, N + 1)]
	if log2(N + 1).is_integer() and K == N - 3:
		return [*range(3, N - 3), *range(N - 2, N + 1)]
	if log2(N + 2).is_integer():
		if K == N - 1:
			return list(range(2, N + 1))
		elif K == N - 2:
			return [*range(1, N - 2), N]
	if not N % 2 and K == N - 1:
		curr = 0
		ans = set(range(1, K + 2))
		for i in ans:
			curr ^= i
		req = 2 ** (int(log2(N)) + 1) - 1
		ans.remove(req - curr)
		return ans
	if N % 2 and K == N - 1:
		if N % 4 == 3:
			return list(range(1, N))
		else:
			return [*range(1, N - 1), N]
	if K == 1:
		return [N]
	if K == N:
		return list(range(1, N + 1))
	l = 2 ** int(log2(N))
	if K == l - 1:
		return [l, *range(1, l - 1)]
	if K < l - 1:
		ans = set()
		ans.update([l, l - 1])
		K -= 2
		if K > 3:
			if K >= l - 8:
				ans.update(range(4, l - 4))
				K -= l - 8
			else:
				ans.update(range(l - 5, l - 5 - K // 4 * 4, -1))
				K %= 4
		if K == 1:
			ans.remove(l - 1)
			ans.update([l - 2, 1])
		elif K == 2:
			ans.remove(l - 1)
			ans.update([l - 4, 2, 1])
		elif K == 3:
			ans.update([1, 2, 3])
		elif K == 4:
			ans.update([l - 2, 1, l - 3, 2])
	else:
		ans = set()
		ans.update([l, *range(1, l - 1)])
		K -= l - 1
		curr = 0
		for num in range(l + 1, l + 2 + K):
			curr ^= num
		ans.update(range(l + 1, l + 2 + K))
		ans.remove(curr)
	return ans
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	print(*opt_xor(N, K))


from math import log2

def optset(n, k):
	if log2(n + 1).is_integer():
		if k == n - 3:
			return [*range(1, n - 3), n]
		if k == n - 2:
			answer = set(range(1, n + 1))
			x = 2 ** int(log2(n))
			answer.remove(x)
			answer.remove(x - 1)
			return answer
	if k == 1:
		return [n]
	elif k == n:
		return list(range(1, n + 1))
	if log2(n + 2).is_integer():
		if k == n - 1:
			return list(range(2, n + 1))
		elif k == n - 2:
			return [*range(1, n - 2), n]
	if n & 1 and k == n - 1:
		return [*range(1, n - 1), n] if n % 4 == 1 else [*range(1, n)]
	x = 2 ** int(log2(n))
	answer = set()
	if k < x - 1:
		answer.add(x)
		answer.add(x - 1)
		k -= 2
		if k > 3:
			if k < x - 8:
				answer.update(range(x - 5, x - 5 - k // 4 * 4, -1))
				k %= 4
			else:
				answer.update(range(4, x - 4))
				k -= x - 8
		if k == 1:
			answer.remove(x - 1)
			answer.add(x - 2)
			answer.add(1)
		elif k == 2:
			answer.remove(x - 1)
			answer.add(x - 4)
			answer.add(2)
			answer.add(1)
		elif k == 3:
			answer.update([1, 2, 3])
		elif k == 4:
			answer.update([1, 2, x - 2, x - 3])
		return answer
	answer = set([*range(1, x - 1), x])
	if k == x - 1:
		return answer
	k -= x - 1
	if k & 1:
		numbers = [*range(x + 1, x + k + 2)]
	else:
		numbers = [*range(x + 1, x + k + 1), x - 1]
	answer.update(numbers)
	curr = 0
	for i in numbers:
		curr ^= i
	answer.remove(curr)
	return answer
for _ in range(int(input())):
	print(*optset(*map(int, input().split())))


import math

def funexat(n, k):
	if k == 0:
		return []
	arr = [i + 1 for i in range(n)]
	ans = []
	ln = len(arr)
	if ln == k:
		return arr
	if k % 2 == 0 and k // 2 % 2 == 1:
		cnt = 0
		while 2 * cnt < k:
			ans.append(arr[cnt])
			ans.append(arr[-2 - cnt])
			cnt += 1
		return ans
	elif (k + 1) % 2 == 0 and (k + 1) // 2 % 2 == 1:
		cnt = 0
		while 2 * cnt < k - 1:
			ans.append(arr[cnt])
			ans.append(arr[-2 - cnt])
			cnt += 1
		ans.append(arr[-1])
		return ans
	elif k < (n + 1) // 2 and k % 2 == 1:
		imm = funexat(n // 2, k - 1)
		ans.append((n + 1) // 2)
		ans += imm
		return ans
	elif k < (n + 1) // 2 and k % 2 == 0:
		imm = funexat(n // 2, k - 3)
		ans.append((n + 1) // 2 + 1)
		ans.append((n + 1) // 2 + 2)
		ans.append((n + 1) // 2 + 3)
		ans += imm
		return ans
	elif k % 2 == 1:
		ans = arr[0:k + 1]
		imm = 1
		for i in ans[1:]:
			imm = imm ^ i
		imm = n - imm
		ans.remove(imm)
		return ans
	elif k % 2 == 0:
		ans = arr[0:k + 2]
		imm = 1
		for i in ans[1:]:
			imm = imm ^ i
		imm = n - imm
		if imm % 2 == 0 and imm != 0:
			ans.remove(imm + 1)
			ans.remove(1)
			return ans
		elif imm != 0:
			ans.remove(imm - 1)
			ans.remove(1)
			return ans
		else:
			ans = arr[:]
			imm = funexat(n, 3)
			for l in imm:
				ans.remove(l)
			return ans
	return [0]

def fun1(arr, num, k):
	ln = len(arr)
	if ln == k:
		return arr
num = int(input())
for t in range(num):
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	arr = []
	for i in range(n):
		arr.append(i + 1)
	dig = math.ceil(math.log(n + 1, 2))
	number = 2 ** (dig - 1) - 1
	n1 = number * 2 + 1
	if k == n:
		ans = arr
	elif k == 1:
		ans = [n]
	elif n == 2 ** dig - 1:
		number = n
		ans = funexat(n, k)
	elif k <= number:
		number = 2 ** (dig - 1) - 1
		ans = funexat(number, k - 1)
		ans.append(number + 1)
	elif k % 2 == 1:
		ans = arr[0:k + 1]
		imm = 1
		for i in ans[1:]:
			imm = imm ^ i
		imm = n1 - imm
		if imm == 0:
			ans.remove(1)
		else:
			ans.remove(imm)
	elif k % 2 == 0 and n >= k + 2:
		ans = arr[0:k + 2]
		imm = 1
		for i in ans[1:]:
			imm = imm ^ i
		imm = n1 - imm
		if imm % 2 == 0 and imm != 0:
			ans.remove(imm + 1)
			ans.remove(1)
		elif imm != 0:
			ans.remove(imm - 1)
			ans.remove(1)
		else:
			ans = arr[:]
			ans.remove(2)
			ans.remove(3)
	else:
		ans = arr
		imm = 1
		for i in ans[1:]:
			imm = imm ^ i
		max1 = 0
		for i2 in ans:
			res = i2 ^ imm
			if res > max1:
				max1 = res
				flg1 = i2
		ans.remove(flg1)
	print(*ans)