Advanced1700

XOUR

Codeforces
View on Codeforces
Time: 2 secondsMemory: 256 megabytes

You are given an array a consisting of n nonnegative integers.

You can swap the elements at positions i and j if a_i~XOR~a_j 4, where XOR is the bitwise XOR operation .

Find the lexicographically smallest array that can be made with any number of swaps.

An array x is lexicographically smaller than an array y if in the first position where x and y differ, x_i y_i.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.The first line of each test case contains a single integer n (1 ≤ n ≤ 2·10^5) — the length of the array.The second line of each test case contains n integers a_i (0 ≤ a_i ≤ 10^9) — the elements of the array.It is guaranteed that the sum of n over all test cases does not exceed 2 · 10^5.

Output

For each test case, output n integers — the lexicographically smallest array that can be made with any number of swaps.

Examples

Input
4 4 1 0 3 2 5 2 7 1 5 6 8 1 2 1 2 1 2 1 2 4 16 4 1 64
Output
0 1 2 3 1 5 2 6 7 1 1 1 1 2 2 2 2 16 4 1 64

Note

For the first test case, you can swap any two elements, so we can produce the sorted array.For the second test case, you can swap 2 and 1 (their XOR is 3), 7 and 5 (their XOR is 2), and 7 and 6 (their XOR is 1) to get the lexicographically smallest array.

data structuresdsusortings

Discussion

(0)
Sign in to join the discussion.
Loading editor...
0 online