CF1625A.Ancient Civilization

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

Ancient Civilization

Martian scientists explore Ganymede, one of Jupiter's numerous moons. Recently, they have found ruins of an ancient civilization. The scientists brought to Mars some tablets with writings in a language unknown to science.

They found out that the inhabitants of Ganymede used an alphabet consisting of two letters, and each word was exactly \ell letters long. So, the scientists decided to write each word of this language as an integer from 00 to 212^{\ell} - 1 inclusively. The first letter of the alphabet corresponds to zero bit in this integer, and the second letter corresponds to one bit.

The same word may have various forms in this language. Then, you need to restore the initial form. The process of doing it is described below.

Denote the distance between two words as the amount of positions, in which these words differ. For example, the distance between 100121001_2 and 110021100_2 (in binary) is equal to two, as these words have different letters in the second and the fourth positions, counting from left to right. Further, denote the distance between words xx and yy as d(x,y)d(x, y).

Let the word have nn forms, the ii-th of which is described with an integer xix_i. All the xix_i are not necessarily different, as two various forms of the word can be written the same. Consider some word yy. Then, closeness of the word yy is equal to the sum of distances to each of the word forms, i. e. the sum d(xi,y)d(x_i, y) over all 1in1 \le i \le n.

The initial form is the word yy with minimal possible nearness.

You need to help the scientists and write the program which finds the initial form of the word given all its known forms. Note that the initial form is not necessarily equal to any of the nn given forms.

Input

The first line contains an integer tt (1t1001 \le t \le 100) — the number of test cases. The following are descriptions of the test cases.

The first line contains two integers nn and \ell (1n1001 \le n \le 100, 1301 \le \ell \le 30) — the amount of word forms, and the number of letters in one word.

The second line contains nn integers xix_i (0xi210 \le x_i \le 2^\ell - 1) — word forms. The integers are not necessarily different.

Output

For each test, print a single integer, the initial form of the word, i. e. such yy (0y210 \le y \le 2^\ell - 1) that the sum d(xi,y)d(x_i, y) over all 1in1 \le i \le n is minimal possible. Note that yy can differ from all the integers xix_i.

If there are multiple ways to restore the initial form, print any.

Note

In the first test case, the words can be written as x1=100102x_1 = 10010_2, x2=010012x_2 = 01001_2 and x3=101012x_3 = 10101_2 in binary. Let y=100012y = 10001_2. Then, d(x1,y)=2d(x_1, y) = 2 (the difference is in the fourth and the fifth positions), d(x2,y)=2d(x_2, y) = 2 (the difference is in the first and the second positions), d(x3,y)=1d(x_3, y) = 1 (the difference is in the third position). So, the closeness is 2+2+1=52 + 2 + 1 = 5. It can be shown that you cannot achieve smaller closeness.

In the second test case, all the forms are equal to 1818 (10010210010_2 in binary), so the initial form is also 1818. It's easy to see that closeness is equal to zero in this case.

Samples

7
3 5
18 9 21
3 5
18 18 18
1 1
1
5 30
1 2 3 4 5
6 10
99 35 85 46 78 55
2 1
0 1
8 8
5 16 42 15 83 65 78 42
17
18
1
1
39
0
2

在线编程 IDE

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