CF1944B.Equal XOR

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

Equal XOR

You are given an array aa of length 2n2n, consisting of each integer from 11 to nn exactly twice.

You are also given an integer kk (1kn21 \leq k \leq \lfloor \frac{n}{2} \rfloor).

You need to find two arrays ll and rr each of length 2k\mathbf{2k} such that:

  • ll is a subset^\dagger of [a1,a2,an][a_1, a_2, \ldots a_n]
  • rr is a subset of [an+1,an+2,a2n][a_{n+1}, a_{n+2}, \ldots a_{2n}]
  • bitwise XOR of elements of ll is equal to the bitwise XOR of elements of rr; in other words, $l_1 \oplus l_2 \oplus \ldots \oplus l_{2k} = r_1 \oplus r_2 \oplus \ldots \oplus r_{2k}$

It can be proved that at least one pair of ll and rr always exists. If there are multiple solutions, you may output any one of them.

^\dagger A sequence xx is a subset of a sequence yy if xx can be obtained by deleting several (possibly none or all) elements of yy and rearranging the elements in any order. For example, [3,1,2,1][3,1,2,1], [1,2,3][1, 2, 3], [1,1][1, 1] and [3,2][3, 2] are subsets of [1,1,2,3][1, 1, 2, 3] but [4][4] and [2,2][2, 2] are not subsets of [1,1,2,3][1, 1, 2, 3].

Input

Each test contains multiple test cases. The first line contains a single integer tt (1t50001 \leq t \leq 5000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains 22 integers nn and kk (2n51042 \le n \le 5 \cdot 10^4, 1kn21 \leq k \leq \lfloor \frac{n}{2} \rfloor).

The second line contains 2n2n integers a1,a2,,a2na_1, a_2, \ldots, a_{2n} (1ain1 \le a_i \le n). It is guaranteed that every integer from 11 to nn occurs exactly twice in aa.

It is guaranteed that the sum of nn over all test cases does not exceed 51045 \cdot 10^4.

Output

For each test case, output two lines.

On the first line of output, output 2k2k integers l1,l2,,l2kl_1, l_2, \ldots, l_{2k}.

On the second line of output, output 2k2k integers r1,r2,r2kr_1, r_2, \ldots r_{2k}.

If there are multiple solutions, you may output any one of them.

Note

In the first test case, we choose l=[2,1]l=[2,1] and r=[2,1]r=[2,1]. [2,1][2, 1] is a subset of [a1,a2][a_1, a_2] and [2,1][2, 1] is a subset of [a3,a4][a_3, a_4], and 21=21=32 \oplus 1 = 2 \oplus 1 = 3.

In the second test case, 64=13=26 \oplus 4 = 1 \oplus 3 = 2.

Samples

4
2 1
1 2 2 1
6 1
6 4 2 1 2 3 1 6 3 5 5 4
4 1
1 2 3 4 1 2 3 4
6 2
5 1 3 3 5 1 2 6 4 6 4 2
2 1
2 1
6 4
1 3
1 2
1 2
5 1 3 3
6 4 2 4

在线编程 IDE

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