CF1696A.NIT orz!

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

NIT orz!

NIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to orz\operatorname{or} z. Can you solve this problem too?

You are given a 1-indexed array of nn integers, aa, and an integer zz. You can do the following operation any number (possibly zero) of times:

  • Select a positive integer ii such that 1in1\le i\le n. Then, simutaneously set aia_i to (aiorz)(a_i\operatorname{or} z) and set zz to (aiandz)(a_i\operatorname{and} z). In other words, let xx and yy respectively be the current values of aia_i and zz. Then set aia_i to (xory)(x\operatorname{or}y) and set zz to (xandy)(x\operatorname{and}y).

Here or\operatorname{or} and and\operatorname{and} denote the bitwise operations OR and AND respectively.

Find the maximum possible value of the maximum value in aa after any number (possibly zero) of operations.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \le t \le 100). Description of the test cases follows.

The first line of each test case contains two integers nn and zz (1n20001\le n\le 2000, 0z<2300\le z \lt 2^{30}).

The second line of each test case contains nn integers a1a_1,a2a_2,\ldots,ana_n (0ai<2300\le a_i \lt 2^{30}).

It is guaranteed that the sum of nn over all test cases does not exceed 10410^4.

Output

For each test case, print one integer — the answer to the problem.

Note

In the first test case of the sample, one optimal sequence of operations is:

  • Do the operation with i=1i=1. Now a1a_1 becomes (3or3)=3(3\operatorname{or}3)=3 and zz becomes (3and3)=3(3\operatorname{and}3)=3.
  • Do the operation with i=2i=2. Now a2a_2 becomes (4or3)=7(4\operatorname{or}3)=7 and zz becomes (4and3)=0(4\operatorname{and}3)=0.
  • Do the operation with i=1i=1. Now a1a_1 becomes (3or0)=3(3\operatorname{or}0)=3 and zz becomes (3and0)=0(3\operatorname{and}0)=0.

After these operations, the sequence aa becomes [3,7][3,7], and the maximum value in it is 77. We can prove that the maximum value in aa can never exceed 77, so the answer is 77.

In the fourth test case of the sample, one optimal sequence of operations is:

  • Do the operation with i=1i=1. Now a1a_1 becomes (7or7)=7(7\operatorname{or}7)=7 and zz becomes (7and7)=7(7\operatorname{and}7)=7.
  • Do the operation with i=3i=3. Now a3a_3 becomes (30or7)=31(30\operatorname{or}7)=31 and zz becomes (30and7)=6(30\operatorname{and}7)=6.
  • Do the operation with i=5i=5. Now a5a_5 becomes (27or6)=31(27\operatorname{or}6)=31 and zz becomes (27and6)=2(27\operatorname{and}6)=2.

Samples

5
2 3
3 4
5 5
0 2 4 6 8
1 9
10
5 7
7 15 30 29 27
3 39548743
10293834 10284344 13635445
7
13
11
31
48234367

在线编程 IDE

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