# [Solution] Mocha and Math solution codeforces

## Mocha and Math solution codeforces

Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.

This day, Mocha got a sequence aa of length nn. In each operation, she can select an arbitrary interval [l,r][l,r] and for all values ii (0irl0≤i≤r−l), replace al+ial+i with al+i&arial+i&ar−i at the same time, where && denotes the bitwise AND operation. This operation can be performed any number of times.

For example, if n=5n=5, the array is [a1,a2,a3,a4,a5][a1,a2,a3,a4,a5], and Mocha selects the interval [2,5][2,5], then the new array is [a1,a2&a5,a3&a4,a4&a3,a5&a2][a1,a2&a5,a3&a4,a4&a3,a5&a2].

Now Mocha wants to minimize the maximum value in the sequence. As her best friend, can you help her to get the answer?

Input Mocha and Math solution codeforces

Each test contains multiple test cases.

The first line contains a single integer tt (1t1001≤t≤100) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains a single integer nn (1n1001≤n≤100) — the length of the sequence.

The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤ai≤109).

Output Mocha and Math solution codeforces

For each test case, print one integer — the minimal value of the maximum value in the sequence.

Example Mocha and Math solution codeforces
input

Copy
4
2
1 2
3
1 1 3
4
3 11 3 7
5
11 7 15 3 7

output

Copy
0
1
3
3

Note

In the first test case, Mocha can choose the interval [1,2][1,2], then the sequence becomes [0,0][0,0], where the first element is 1&21&2, and the second element is 2&12&1.

In the second test case, Mocha can choose the interval [1,3][1,3], then the sequence becomes [1,1,1][1,1,1], where the first element is 1&31&3, the second element is 1&11&1, and the third element is 3&13&1.