description: 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 (0≤ i ≤ r-l), replace a_{l+i} with a_{l+i}  \&  a_{r-i} at the same time, where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). This operation can be performed any number of times.
  
  For example, if n=5, the array is [a_1,a_2,a_3,a_4,a_5], and Mocha selects the interval [2,5], then the new array is [a_1,a_2 \&  a_5, a_3 \&  a_4, a_4 \&  a_3, a_5 \&  a_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 (1 ≤ 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 n (1 ≤ n ≤ 100) — the length of the sequence.
  
  The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9).
  
  Output
  
  For each test case, print one integer — the minimal value of the maximum value in the sequence.
  
  Example
  
  Input
  
  
  4
  2
  1 2
  3
  1 1 3
  4
  3 11 3 7
  5
  11 7 15 3 7
  
  
  Output
  
  
  0
  1
  3
  3
  
  Note
  
  In the first test case, Mocha can choose the interval [1,2], then the sequence becomes [ 0, 0], where the first element is 1 \& 2, and the second element is 2 \& 1.
  
  In the second test case, Mocha can choose the interval [1,3], then the sequence becomes [ 1,1,1], where the first element is 1 \& 3, the second element is 1 \& 1, and the third element is 3 \& 1.
solution: 
  import java.io.BufferedReader;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.*;
          //import java.util.*;
      public class Solution {
  
          static class FastScanner {
  
                  BufferedReader br;
                  StringTokenizer st ;
  
                  FastScanner(){
                      br =  new BufferedReader(new InputStreamReader(System.in));
                      st = new StringTokenizer("");
                  }
  
                  FastScanner(String file) {
  
                      try {
                          br =  new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                          st = new StringTokenizer("");
                      } catch (FileNotFoundException e) {
                          // TODO Auto-generated catch block
                          System.out.println("file not found");
                          e.printStackTrace();
                      }
                      
                  }
                  
  
                  String next() {
                      while (!st.hasMoreTokens())
                          try {
                              st = new StringTokenizer(br.readLine());
                          } catch (IOException e) {
                          }
                      return st.nextToken();
                  }
  
                  int nextInt() {
                      return Integer.parseInt(next());
                  }
  
                  long nextLong() {
                      return Long.parseLong(next());
                  }
                  String readLine() throws IOException{
                      return br.readLine();
                  }
              }
                                    
          static class Pair{
              String word;
              int cnt;
              Pair(String word,int cnt){
                  this.word = word;
                  this.cnt = cnt;
              }
  
          }
  
          
  
       public static void main(String[] args) throws Exception {
          
          FastScanner s = new FastScanner();
  
          //Scanner s = new Scanner(System.in);
  
          int t = s.nextInt();
  
          for(int tc=0;tc<t;tc++){
              
              int n = s.nextInt();
  
              long arr[] = new long[n];
  
              for(int i=0;i<n;i++){
                  arr[i] = s.nextLong();
              }
  
              for(int len=2;len<=n;len++){
                  
                  int st = 0;
                  int e = st + len - 1;
                  
                  while(e < n){
  
                      int i = st;
                      int j = e;
  
                      while(i<=j){
                          arr[i] = arr[j] = (arr[i]&arr[j]);
                          i++;
                          j--;
                      }
  
                      st++;
                      e = st+len-1;
                  }
              }
  
              long min = Long.MAX_VALUE;
              for(int i=0;i<n;i++){
                  min = Math.min(min,arr[i]);
              }
              System.out.println(min);
          }
      }
  
      public static long get(long i,int arr[]){
  
          if(i<=0){
              return 0l;
          }
  
          long ans = 0;
  
          long times = (i / arr.length);
  
          ans += (times * arr[arr.length - 1]);
  
          int rem = (int)(i % (arr.length));
          
          ans += arr[rem];
        
          return ans;
      }
  
    
  
      public static List<Integer> sieve(){
         
          List<Integer> prime = new ArrayList<>();
  
          int arr[] = new int[100001];
  
          Arrays.fill(arr,1);
  
          arr[1] = 0;
          arr[2] = 1;
  
          for(int i=2;i<=100000;i++){
              
              if(arr[i] == 1){
                  
                  prime.add(i);
  
                  for(long j = (i*1l*i);j<100001;j+=i){
                      arr[(int)j] = 0;
                  }
              }
          }
  
          return prime;
      }
  
      static boolean isPower(long n,long a){
          
          long log = (long)(Math.log(n)/Math.log(a));
  
          long power = (long)Math.pow(a,log);
  
          if(power == n){return true;}
  
          return false;
      }
  
  
      private static int mergeAndCount(int[] arr, int l,int m, int r)
      {
  
          // Left subarray
          int[] left =  Arrays.copyOfRange(arr, l, m + 1);
  
          // Right subarray
          int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
  
          int i = 0, j = 0, k = l, swaps = 0;
  
          while (i < left.length && j < right.length) {
              if (left[i] <= right[j])
                  arr[k++] = left[i++];
              else {
                  arr[k++] = right[j++];
                  swaps += (m + 1) - (l + i);
              }
          }
          while (i < left.length)
              arr[k++] = left[i++];
          while (j < right.length)
              arr[k++] = right[j++];
          return swaps;
      }
  
      // Merge sort function
      private static int mergeSortAndCount(int[] arr, int l,int r)
      {
  
          // Keeps track of the inversion count at a
          // particular node of the recursion tree
          int count = 0;
  
          if (l < r) {
              int m = (l + r) / 2;
  
              // Total inversion count = left subarray count
              // + right subarray count + merge count
  
              // Left subarray count
              count += mergeSortAndCount(arr, l, m);
  
              // Right subarray count
              count += mergeSortAndCount(arr, m + 1, r);
  
              // Merge count
              count += mergeAndCount(arr, l, m, r);
          }
  
          return count;
      }
  
  }
  