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.IOException;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.Map;
  import java.util.Queue;
  import java.util.Scanner;
  import java.util.Set;
  import java.util.Stack;
  
  public class Codeforces {
  
  
  	static Scanner sc=new Scanner(System.in);
  
  	public static void main(String[] args) throws IOException {
  		int t=1;
  		t=sc.nextInt();
  
  		while(t-->0) {
  			solve();
  
  		}
  
  	}
  
  
  
  	private static void solve() throws IOException {
  
  		int n=sc.nextInt();
  		int arr[]=new int[n];
  		for(int i=0;i<n;i++) {
  			arr[i]=sc.nextInt();
  		}
  		
  		int min=arr[0];
  		for(int i=1;i<n;i++) {
  			min=min&arr[i];
  		}
  		System.out.println(min);
  		
  		/*InputStreamReader r=new InputStreamReader(System.in);    
  		BufferedReader br=new BufferedReader(r); 
  
  		String s=br.readLine();
  		String str[]=s.split(" ");
  		int n=Integer.parseInt(str[0]);
  		long k=Long.parseLong(str[1]);
  		long x=Long.parseLong(str[2]);
  		//System.out.println(n+" "+k+" "+x);
  
  		//int n=sc.nextInt();
  		//long k=sc.nextLong();
  		//long x=sc.nextLong();
  
  		long arr[]=new long[n];
  
  		String s1=br.readLine();
  		//System.out.println(s1);
  		String str1[]=s1.split(" ");
  		//System.out.println(str1.length);
  		for(int i=0;i<n;i++) {
  			arr[i]=Long.parseLong(str1[i]);
  		}
  		Arrays.sort(arr);
  
  		ArrayList<Long> list=new ArrayList<Long>(n-1);
  		for(int i=0;i<n-1;i++) {
  			long t=(arr[i+1]-arr[i]);
  			if(t>x) {
  				list.add(t);
  			}
  		}
  
  		Collections.sort(list);
  		
  		int ans=list.size()+1;
  		
  		for(int i=0;i<list.size();i++) {
  			if(list.get(i)>x) {
  				long fill=(list.get(i)-1)/x;
  				if(fill<=k) {
  					ans--;
  					k-=fill;
  				}else {
  					break;
  				}
  
  			}
  			if(k<=0){
  				break;
  			}
  		}
  		
  
  		System.out.println(ans);
  
  		/*int n=sc.nextInt();
  		String s1=sc.next();
  		String s2=sc.next();
  
  		int count=0;
  		boolean isVisted[]=new boolean[n];
  		for(int i=0;i<n;i++) {
  
  			if(s2.charAt(i)=='1' && s1.charAt(i)=='0') {
  				count++;
  
  			}else if( s2.charAt(i)=='1' && i-1>=0 && isVisted[i-1]==false && s1.charAt(i-1)=='1') {
  				count++;
  			}else if( s2.charAt(i)=='1' && i+1<n && s1.charAt(i+1)=='1') {
  				count++;
  				isVisted[i+1]=true;
  				//s1=s1.substring(0,i+1)+'5'+s1.substring(i+2,s1.length());
  			}
  		}
  
  		System.out.println(count);
  
  		/*long p=sc.nextLong();
  
  		long a=0;
  		long b=p-1;
  		for(long i=2;i<b;i++) {
  			if(b%i==0) {
  				a=i;
  				break;
  			}
  		}
  		System.out.println(a+" "+b);
  
  		/*int n=sc.nextInt();
  		long arr[]=new long[n+1];
  		for(int i=1;i<=n;i++) {
  			arr[i]=sc.nextInt();
  		}
  		int count=0;
  
  		for (int i = 1; i <= n; i++)
          {
              for (int j =(int) arr[i] - i; j <= n; j += arr[i])
              {
                  if (j >= 0)
                      if (arr[i] * arr[j] == i + j && i < j)
                          count++;
              }
          }
  
  		System.out.println(count);
  
  		/*int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		String input[]=new String[n];
  
  		String out[]=new String[n-1];
  
  		for(int i=0;i<n;i++) {
  			input[i]=sc.next();
  		}
  
  		if(n==1) {
  			System.out.println(input[0]);
  			return ;
  		}
  
  		for(int i=0;i<n-1;i++) {
  			out[i]=sc.next();
  		}
  
  
  		String s="";
  		for(int i=0;i<m;i++) {
  			int sum=0;
  			for(int j=0;j<n;j++) {
  				sum+=input[j].charAt(i);
  				if(j<n-1) {
  					sum-=out[j].charAt(i);
  				}
  			}
  
  			s=s+ (char)sum;
  
  			//System.out.println(s);
  
  		}
  
  		System.out.println(s);
  
  
  
  		/*long k=sc.nextLong();
  
  		long squarRoot=(long)Math.floor(Math.sqrt(k-1));
  		squarRoot++;
  
  		long fillF=(squarRoot-1)*(squarRoot-1)+1;
  		//System.out.println(fillF);
  		if(k-fillF<squarRoot) {
  			System.out.println((k-fillF+1)+" "+squarRoot);
  		}else {
  			System.out.println(squarRoot+" "+((squarRoot*squarRoot)-k+1));
  		}
  
  
  		/*int a=sc.nextInt();
  		int b=sc.nextInt();
  		int c=sc.nextInt();
  
  		int total=2*Math.abs(a-b);
  
  		if(Math.min(a, b)-1> Math.abs(a-b)-1 || c>total ) {
  			System.out.println(-1);
  			return;
  		}
  
  		int d= ((total+ 2*c )/2)%total;
  		if(d==0) {
  			System.out.println(total);
  		}else {
  			System.out.println(d);
  		}
  
  
  		/*int k=sc.nextInt();
  
  		int n=1;
  		int i=1;
  		while(i<k) {
  			n++;
  			if(!(n%3==0 || n%10==3)) {
  				i++;
  			}
  
  		}
  
  		System.out.println(n);
  
  		 */
  
  
  
  		/*int k=sc.nextInt();
  		int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		int arr1[]=new int[n];
  		int arr2[]=new int[m];
  
  		for(int i=0;i<n;i++) {
  			arr1[i]=sc.nextInt();
  		}
  		for(int j=0;j<m;j++) {
  			arr2[j]=sc.nextInt();
  		}
  		int i=0;
  		int j=0;
  		boolean turn=true;
  		int a=0;
  		int ans[]=new int[m+n];
  
  		while(i<n && j<m) {
  			if(arr1[i]==0) {
  				ans[a++]=arr1[i++];
  				k++;
  				continue;
  			}
  			if(arr2[j]==0) {
  				ans[a++]=arr2[j++];
  				k++;
  				continue;
  			}
  			if(arr1[i]<arr2[j]) {
  				if(arr1[i]>k) {
  					System.out.println(-1);
  					return;
  				}else {
  					ans[a++]=arr1[i++];
  				}
  			}else {
  				if(arr2[j]>k) {
  					System.out.println(-1);
  					return;
  				}else {
  					ans[a++]=arr2[j++];
  				}
  			}
  
  		}
  		while(i<n) {
  			if(arr1[i]==0) {
  				ans[a++]=arr1[i++];
  				k++;
  				continue;
  			}
  			if(arr1[i]>k) {
  				System.out.println(-1);
  				return;
  			}else {
  				ans[a++]=arr1[i++];
  			}
  		}
  
  		while(j<m) {
  			if(arr2[j]==0) {
  				ans[a++]=arr2[j++];
  				k++;
  				continue;
  			}
  			if(arr2[j]>k) {
  				System.out.println(-1);
  				return;
  			}else {
  				ans[a++]=arr2[j++];
  			}
  		}
  
  		for(i=0;i<m+n;i++) {
  			System.out.print(ans[i]+" ");
  		}
  		System.out.println();
  		/*int r=sc.nextInt();
  		int b=sc.nextInt();
  		int d=sc.nextInt();
  
  		int min=Math.min(r,b);
  
  		int red=(r+min-1)/min;
  		int blue=(b+min-1)/min;
  		if(Math.abs(red-blue)<=d) {
  			System.out.println("YES");
  		}else {
  			System.out.println("NO");
  		}
  
  
  		/*int n=sc.nextInt();
  		int m=sc.nextInt();
  		int k=sc.nextInt();
  
  		int tCost=(m-1)+(n-1)*m;
  
  		if(k==tCost) {
  			System.out.println("YES");
  		}else {
  			System.out.println("NO");
  		}
  
  		/*int n=sc.nextInt();
  		String s=sc.next().substring(0,n);
  		Set<Character> set=new HashSet<Character>();
  
  		set.add(s.charAt(0));
  		for(int i=1;i<s.length();i++) {
  			if(s.charAt(i)==s.charAt(i-1)) {
  				continue;
  			}
  			if(set.contains(s.charAt(i))) {
  				System.out.println("NO");
  				return;
  			}
  			set.add(s.charAt(i));
  		}
  		System.out.println("YES");
  
  		/*long n=sc.nextLong();
  		if(n<10) {
  			System.out.println(n);
  			return;
  		}
  
  		Queue<Long> q=new LinkedList<Long>();
  		for(long i=1;i<10;i++) {
  			q.add(i);
  		}
  		int count=0;
  		while(q.peek()<=n) {
  			count++;
  			long front=q.poll();
  			q.add(front*10+(front%10));
  		}
  		System.out.println(count);
  
  		/*int n=sc.nextInt();
  
  		if(n==1) {
  			System.out.println(1);
  			return ;
  		}
  		if(n==2) {
  			System.out.println(-1);
  			return;
  		}
  
  		int arr[][]=new int[n][n];
  		fill(arr);
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<n;j++) {
  				System.out.print(arr[i][j]+" ");
  			}
  			System.out.println();
  		}
  
  
  		/*
  		int a=sc.nextInt();
  		int b=sc.nextInt();
  
  		if(b==1) {
  			System.out.println("NO");
  			return;
  		}
  
  		long x=a;
  		long y= (1L*a*b);
  		long z=x+y;
  
  		System.out.println("YES");
  		System.out.println(x+" "+y+" "+z);
  
  		/*int n=sc.nextInt();
  		int t=sc.nextInt();
  		String s=sc.next().substring(0,n);
  
  		Stack<Integer> st=new Stack<Integer>();
  		for(int i=n-1;i>=0;i--) {
  			if(s.charAt(i)=='1') {
  				st.push(i);
  			}
  		}
  		Stack<Integer> left=new Stack<Integer>();
  		for(int i=0;i<n;i++) {
  			if(s.charAt(i)=='1') {
  				left.push(i);
  				st.pop();
  			}else {
  				if(st.isEmpty() && left.isEmpty()) {
  					System.out.println(s);
  					return;
  				}else if(left.isEmpty()) {
  					int rightO=st.peek();
  					if(rightO-i<=t) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}else if(st.isEmpty()) {
  					int leftIndex=left.peek();
  					if(i-leftIndex<=t) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}else {
  					int rightO=st.peek();
  					int leftIndex=left.peek();
  					if(i-leftIndex != rightO-i && (i-leftIndex<=t || rightO-i<=t )) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}
  			}
  
  		}
  		System.out.println(s);
  
  
  		/*
  		int n=sc.nextInt();
  		int arr[]=new int[2*n];
  		for(int i=0;i<2*n;i++) {
  			arr[i]=sc.nextInt();
  		}
  		Arrays.sort(arr);
  		int i=0;
  		int j=n;
  		int arr2[]=new int[2*n];
  		int k=0;
  		while(k<2*n) {
  			if(k%2==0) {
  				arr2[k++]=arr[i++];
  			}else {
  				arr2[k++]=arr[j++];
  			}
  		}
  
  		for(i=0;i<2*n;i++) {
  			System.out.print(arr2[i]+" ");
  		}
  		System.out.println();
  
  
  
  
  		/*long n=sc.nextLong();
  
  		long ans=n;
  		int i=1;
  
  		for(;;i++) {
  			if((Math.pow(2,i)-1)>=n) {
  				break;
  			}
  		}
  		System.out.println((long)Math.pow(2,i-1)-1);
  
  
  		/*
  		//Binary Decimal
  
  		long l=sc.nextLong();
  		long max=0;
  		while(l>0) {
  			max=Math.max(max, l%10);
  			l/=10;
  		}
  		System.out.println(max);
  
  		/*
  		//B. Putting Plates
  
  		int m=sc.nextInt();
  		int n=sc.nextInt();
  
  		int arr[][]=new int[m][n];
  		for(int i=0;i<n;i++) {
  			if(i%2==0) {
  				arr[0][i]=1;
  				arr[m-1][i]=1;
  			}
  		}
  
  		for(int i=2;i<m-2;i++) {
  			if(i%2==0) {
  				arr[i][0]=1;
  				arr[i][n-1]=1;
  			}
  		}
  
  		for(int i=0;i<m;i++) {
  			for(int j=0;j<n;j++) {
  				System.out.print(arr[i][j]);
  			}
  			System.out.println();
  		}
  
  
  		/*
  		//Colour the flag 
  		int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		char arr[][]=new char[n][m];
  
  		for(int i=0;i<n;i++) {
  			String s=sc.next();
  			for(int j=0;j<m;j++) {
  				arr[i][j]=s.charAt(j);
  			}
  		}
  
  		boolean isRed=false;
  		int row=0;
  		int col=0;
  		for(int i=0;i<n;i++) {
  			boolean get=false;
  			for(int j=0;j<m;j++) {
  				if(arr[i][j]=='R') {
  					isRed=true;
  					row=i;
  					col=j;
  					get=true;
  					break;
  				}
  				if(arr[i][j]=='W') {
  					row=i;
  					col=j;
  					get=true;
  					break;
  				}
  			}
  			if(get)
  				break;
  		}
  		char color;
  		char color1;
  		if(isRed) {
  			color='R';
  			color1='W';
  		}else {
  			color='W';
  			color1='R';
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				if((i%2==row%2 && j%2==col%2) || (i%2!=row%2 && j%2!=col%2) ) {
  					if( !(arr[i][j]==color || arr[i][j]=='.')  ) {
  						System.out.println("NO");
  						return ;
  					}
  				}else {
  					if(arr[i][j]==color) {
  						System.out.println("NO");
  						return ;
  					}
  				}
  			}
  		}
  
  		System.out.println("YES");
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				if((i%2==row%2 && j%2==col%2) || (i%2!=row%2 && j%2!=col%2) ) {
  					arr[i][j]=color;
  				}else {
  					arr[i][j]=color1;
  				}
  			}
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				System.out.print(arr[i][j]);
  			}
  			System.out.println();
  		}
  		 */
  	}
  
  
  
  	private static int __gcd(int i, int j) {
  		if(i%j==0) {
  			return j;
  		}
  
  		return __gcd(j, i%j );
  	}
  
  	private static void fill(int[][] arr) {
  
  
  
  		/*int n=arr.length;
  
  		int count=1;
  		for(int i=0;i<n;i++) {
  			arr[i][i]=count++;
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<i;j++) {
  				arr[i][j]=count++;
  				arr[j][i]=count++;
  			}
  		}
  
  		/*
  		if(i>=n)
  			return true;
  
  		for(int k=1;k<=n*n;k++) {
  			if(!set.contains(k)) {
  				int count=0;
  				if(i-1>=0 && Math.abs(k-arr[i-1][j])==1) {
  					count++;
  				}
  				if(i+1<n && Math.abs(k-arr[i+1][j])==1) {
  					count++;
  				}
  				if(j-1>=0 && Math.abs(k-arr[i][j-1])==1) {
  					count++;
  				}
  				if(j+1<n && Math.abs(k-arr[i][j+1])==1) {
  					count++;
  				}
  				if(count==0) {
  					arr[i][j]=k;
  					//System.out.println(k);
  					set.add(k);
  					if(j==n-1) {
  						if(!fill(arr,i+1,0,set)) {
  							arr[i][j]=-5;
  							set.remove(k);
  						}else {
  							return true;
  						}
  					}else {
  						if(!fill(arr,i,j+1,set)) {
  							arr[i][j]=-5;
  							set.remove(k);
  						}else {
  							return true;
  						}
  					}
  
  				}
  
  			}
  		}
  		return false;
  		 */
  	}
  
  
  
  }
  