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: //package competitveprogramming;
  import java.util.*;
  import java.math.*;
  import java.io.*;
  public class Main
  {
      //By shwetank_verma
  	public static void main(String[] args)
      {
          FastReader sc=new FastReader();
          
                  int t=1;
                  t=sc.nextInt();
                  while(t-->0){
                  	int n=sc.nextInt();
                  	int a[]=new int[n];
                  	for(int i=0;i<n;i++)
                  		a[i]=sc.nextInt();
                  	int ans=a[0];
                  	for(int i=1;i<n;i++) {
                  		ans=ans&a[i];
                  	}
                  	System.out.println(ans);
                  }
      }
  
  static void ruffleSort(long[] a) {
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			long oi=r.nextInt(n), temp=a[i];
  			a[i]=a[(int)oi];
  			a[(int)oi]=temp;
  		}
  		Arrays.sort(a);
  	}
  static void ruffleSort(int[] a) {
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			int oi=r.nextInt(n), temp=a[i];
  			a[i]=a[oi];
  			a[oi]=temp;
  		}
  		Arrays.sort(a);
  	}
  static long fact[];
  static long mod_pow(long a , long n , long mod){
      if(n == 0){
          return 1;
      }
      long res = mod_pow((a*a)%mod , n/2 , mod);
      if(n % 2!=0){
          res = (res*a)%mod;
      }
      return res;
  }
  static long mod_inv(long x , long mod){
      return mod_pow(x , mod - 2 , mod);
  }
  static long nCr(int n , int r , long mod){
      return ((fact[n]*mod_inv(fact[r] , mod) % mod)* (mod_inv(fact[n - r] , mod) % mod))%mod;
  }
  static void factorial(int n,long mod){
  	fact=new long[n+1];
      fact[0] = 1;
      for(int i = 1; i < n; i++){
          fact[i] = (i*fact[i - 1]);
          fact[i] %= mod;
      }
  }
  static boolean visited[][];
  static int dx[]= {-1,0,1,0};
  static int dy[]= {0,1,0,-1};
  static boolean isValid(char ch[][],int x,int y,int n,int m) {
  	if(x<0||x>=n||y<0||y>=m) {
  		return false;
  	}
  	if(ch[x][y]=='#'||visited[x][y]) {
  		return false;
  	}
  	return true;
  	
  }
  static void dfs(char ch[][],int x,int y,int n,int m) {
  	visited[x][y]=true;
  	for(int i=0;i<4;i++) {
  		if(isValid(ch,x+dx[i],y+dy[i],n,m))
  		dfs(ch,x+dx[i],y+dy[i],n,m);
  	}
  }
  static class Point implements Comparable<Point>
  {
      int x, y;
      Point(int x, int y)
      {
          this.x = x;
          this.y = y;
      }
      
      public int compareTo(Point P)
      {
          return this.x - P.x;
      }
  }
  static void leftrotate(int arr[],int n,int d) {
  	reverse(arr,0,d-1);
  	reverse(arr,d,n-1);
  	reverse(arr,0,n-1);
  }
  static void reverse(int arr[],int low,int high) {
  	while(low<high) {
  		int temp=arr[low];
  		arr[low]=arr[high];
  		arr[high]=temp;
  		low++;
  		high--;
  	}
  }
      static class FastReader
      {
          BufferedReader br;
          StringTokenizer st;
    
          public FastReader()
          {
              br = new BufferedReader(new
                       InputStreamReader(System.in));
          }
    
          String next()
          {
              while (st == null || !st.hasMoreElements())
              {
                  try
                  {
                      st = new StringTokenizer(br.readLine());
                  }
                  catch (IOException  e)
                  {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
    
          int nextInt()
          {
              return Integer.parseInt(next());
          }
    
          long nextLong()
          {
              return Long.parseLong(next());
          }
    
          double nextDouble()
          {
              return Double.parseDouble(next());
          }
    
          String nextLine()
          {
              String str = "";
              try
              {
                  str = br.readLine();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
              return str;
          }
      }
      static int mod=1000000007;
      static boolean primes[]=new boolean[100002];
      static ArrayList<Integer> b=new ArrayList<>();
      static boolean seive(int n){
          Arrays.fill(primes,true);
          primes[0]=primes[1]=false;
          for(int i=2;i*i<=n;i++){
              if(primes[i]==true){
                  for(int p=i*i;p<=n;p+=i){
                      primes[p]=false;
                  }
              }
          }
          if(n<1000007){
          	for(int i=2;i<=n;i++) {
          		if(primes[i])
          			b.add(i);
          	}
              return primes[n];
          }
          return false;
          
      }
      static int gcd(int a,int b){
          if(b==0)
          return a;
          return gcd(b,a%b);
      }
      static long GCD(long a,long b){
          if(b==0)
          return a;
          return GCD(b,a%b);
      }
      static ArrayList<Integer> segseive(int l,int r){
      	
      	ArrayList<Integer> isprime=new ArrayList<Integer>();
      	boolean p[]=new boolean[r-l+1];
      	Arrays.fill(p, true);
          
      	for(int i=0;b.get(i)*b.get(i)<=r;i++) {
      		int currprime=b.get(i);
      		int base=(l/currprime)*currprime;
      		if(base<l) {
      			base+=currprime;
      		}
      		for(int j=base;j<=r;j+=currprime) {
      			p[j-l]=false;
      		}
      		
      		
      		if(base==currprime) {
      			p[base-l]=true;
      		}
      		
      	}
      	for(int i=0;i<=r-l;i++) {
      		if(p[i])
      			isprime.add(i+l);
      	}
      	return isprime;
      }
        static int LowerBound(int a[], int x) { // x is the target value or key
    int l=-1,r=a.length;
    while(l+1<r) {
      int m=(l+r)>>>1;
      if(a[m]>=x) r=m;
      else l=m;
    }
    return r;
  }
  static int UpperBound(int a[], int x) {// x is the key or target value
      int l=-1,r=a.length;
      while(l+1<r) {
         int m=(l+r)>>>1;
         if(a[m]<=x) l=m;
         else r=m;
      }
      return l+1;
   }
  
    
       
  }
  