Algorithm


A. Mocha and Math
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a of length n. In each operation, she can select an arbitrary interval [l,r][�,�] and for all values i (0irl0≤�≤�−�), replace al+i��+� with al+i&ari��+�&��−� at the same time, where && denotes the bitwise AND operation. This operation can be performed any number of times.

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

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

Input

Each test contains multiple test cases.

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

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

The second line of each test case contains n integers a1,a2,,an�1,�2,…,�� (0ai1090≤��≤109).

Output

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

Example
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.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll t;
  cin>>t;
  while(t--){
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i = 0; i < n; i++){
      cin>>arr[i];
    }
    ll res = arr[0];

    for(ll i = 1; i < n; i++){
      res &= arr[i];
    }
    cout<<res<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
2
1 2
3
1 1 3
4
3 11 3 7
5
11 7 15 3 7

Output

x
+
cmd
0
1
3
3
Advertisements

Demonstration


Codeforcess Solution  1559-A A. Mocha and Math ,C++, Java, Js and Python,1559-A,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+