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.*;
  import java.util.*;
  
  public class Main {
  
      static int M = 1_000_000_007;
      static int INF = 2_000_000_000;
      static int N = (int)1e5+1;
      static final FastScanner fs = new FastScanner();
  
      //variable
  
      public static void main(String[] args) throws IOException {
  
          int T = fs.nextInt();
          while(T-- > 0) {
              int n = fs.nextInt();
              int[] arr = fs.arrayIn(n);
              int ans = arr[0];
              for(int i=1;i<n;i++) {
                  ans &= arr[i];
              }
              System.out.println(ans);
          }
  
  
      }
      //class
  
      //function
      static int matchCount( char[] X, char[] Y, int m, int n ) {
          int ans = 0;
          int j = 0;
          for(int k=0;j<m && k<n;k++) {
              if(Y[k] == X[j]){
                  ans++;
                  j++;
              }
          }
  
          return ans;
      }
      static void build(int a[],int seg[],int ind,int low,int high)
      {
          if(low == high)
          {
              seg[ind] = a[low];
              return;
          }
  
          int mid = (low + high)/2;
          build(a, seg, 2*ind + 1, low, mid);
          build(a, seg, 2*ind + 2, mid + 1, high);
  
          seg[ind] = Math.max(seg[2*ind + 1], seg[2*ind + 2]);
      }
  
      static long query(int ind, int seg[], int l, int h, int low, int high)
      {
          if(low > h || high < l) return -INF;
  
          if(low >= l && high <= h) return seg[ind];
  
          int mid = (low + high)/2;
          long left = query(2*ind + 1, seg, l, h, low, mid);
          long right = query(2*ind + 2, seg, l, h, mid + 1, high);
  
          return Math.max(left, right);
      }
      // Template
      static long factorial(int n) {
          long fact = 1;
          for(int i=1;i<=n;i++) {
              fact *= i;
          }
          return fact;
      }
      static long lcm(long a, long b) {
          return (a / gcd(a, b)) * b;
      }
  
      static long gcd(long a, long b) {
          if(a==0) return b;
  
          return gcd(b%a,a);
      }
      static void premutation(int n, ArrayList<Integer> arr,boolean[] chosen) {
          if(arr.size() == n) {
              System.out.println(arr);
          }else {
              for(int i=1; i<=n; i++) {
                  if(chosen[i]) continue;
                  arr.add(i);
                  chosen[i] = true;
                  premutation(n,arr,chosen);
                  arr.remove(new Integer(i));
                  chosen[i] = false;
              }
          }
      }
      static boolean isPalindrome(char[] c) {
          int n = c.length;
          for(int i=0; i<n/2; i++) {
              if(c[i] != c[n-i-1]) return false;
          }
          return true;
      }
  
      static long nCk(int n, int k) {
          return (modMult(fact(n),fastexp(modMult(fact(n-k),fact(k)),M-2)));
      }
  
      static long fact (long n) {
  
          long fact =1;
          for(int i=1; i<=n; i++) {
              fact = modMult(fact,i);
          }
          return fact%M;
      }
  
      static int modMult(long a,long b) {
          return (int) (a*b%M);
      }
      static int negMult(long a,long b) {
          return (int)((a*b)%M + M)%M;
      }
      static long fastexp(long x, int y){
          if(y==1) return x;
          if(y == 0) return 1;
          long ans = fastexp(x,y/2);
          if(y%2 == 0) return modMult(ans,ans);
          else return modMult(ans,modMult(ans,x));
      }
  
      static final Random random = new Random();
  
      static void ruffleSort(int[] arr)
      {
          int n = arr.length;
          for(int i=0; i<n; i++)
          {
              int j = random.nextInt(n);
              int temp = arr[j];
              arr[j] = arr[i];
              arr[i] = temp;
          }
          Arrays.sort(arr);
      }
  
  
      public static class Pairs implements Comparable<Pairs>
      {
          int f,s;
          Pairs(int f, int s)
          {
              this.f = f;
              this.s = s;
          }
          public int compareTo(Pairs p)
          {
              if(this.f != p.f) return Integer.compare(this.f,p.f);
  
              return -Integer.compare(this.s,p.s);
          }
  
          @Override
          public boolean equals(Object o) {
              if (this == o) return true;
              if (!(o instanceof Pairs)) return false;
              Pairs pairs = (Pairs) o;
              return f == pairs.f && s == pairs.s;
          }
  
          @Override
          public int hashCode() {
              return Objects.hash(f, s);
          }
      }
  }
  class FastScanner
  {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer str = new StringTokenizer("");
  
      String next() throws IOException
      {
          while(!str.hasMoreTokens())
              str = new StringTokenizer(br.readLine());
  
          return str.nextToken();
      }
  
      char nextChar() throws IOException {
          return next().charAt(0);
      }
  
      int nextInt() throws IOException
      {
          return Integer.parseInt(next());
      }
  
      float nextFloat() throws IOException
      {
          return Float.parseFloat(next());
      }
  
      double nextDouble() throws IOException
      {
          return Double.parseDouble(next());
      }
      long nextLong() throws IOException
      {
          return Long.parseLong(next());
      }
      byte nextByte() throws IOException
      {
          return Byte.parseByte(next());
      }
      int [] arrayIn(int n) throws IOException
      {
          int[] arr = new int[n];
          for(int i=0; i<n; i++)
          {
              arr[i] = nextInt();
          }
          return arr;
      }
  }