The And Problem#12233

The And Problem

1 second
256 megabytes
Medium

You are given an array of positive integers a_1, a_2, \dots, a_n.

In one move, you may choose any two distinct indices i \ne j and replace

(a_i, a_j) \ \to \ (a_i \ \& \ a_j, \ a_i \ \& \ a_j)

where denotes the bitwise AND operation.

You may repeat this operation arbitrarily many times.

For each test case, determine the smallest integer such that it is possible to make appear at least times in the array.

Input

The first line contains a single integer (1 \le t \le 1000) — the number of test cases.

The first line of each test case contains an integer (3 \le n \le 10^6) — the size of the array.

The second line of each test case contains integers a_1, a_2, \dots, a_n (1 \le a_i \le 10^9) — the elements of the array.

It is guaranteed that the sum of over all test cases does not exceed 10^6.

Output

For each test case, print a single integer — the smallest value that can appear at least times after performing the operation any number of times.

Examples

Example 1

Loading
Loading

Note

In the first test case, we already have elements, of which is the smallest value.

In the second test case, since 1 \& 2 = 0, the array becomes: [0,0,3,4,5] and since 3 \& 0 = 0, the array further becomes: [0,0,0,4,5] Thus, there are zeros in the array, which is the minimum possible.

Scoring

  1. Subtask ( points) : (a_1=a_2=...=a_n)

  2. Subtask ( points) : (1 \le \sum n \le 1000)

  3. Subtask ( points) : one bit position is set in every element in .

  4. Subtask ( points) : There exist exactly two distinct integers in .

  5. Subtask ( points) : No additional constraints.