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 os, sys
  import math
  from io import BytesIO, IOBase
  from collections import Counter
  
  # Fast IO Region
  BUFSIZE = 8192
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
  
  
  sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  
  
  def sieve(n):
      p = [1 for i in range(n + 1)]
      z = 2
      while z * z <= n:
          if p[z] == 1:
              for i in range(z * z, n + 1, z):
                  p[i] = 0
          z += 1
      primes = [2]
      for i in range(3, n + 1, 2):
          if p[i]:
              primes.append(i)
      return primes
  
  
  def ordinarynunm(x):
      ans = 0
      k = 0
      for i in range(9):
          k = k + 10 ** i
          for t in range(1, 10):
              if t * k <= x:
                  ans += 1
      return ans
  
  
  def findodddivisor(x):
      while x >= 2:
          x = x / 2
      if x == 1:
          return "NO"
      else:
          return "YES"
  
  
  def bins(arr, n, k):
      l = 0
      r = n - 1
      leftGreater = n
      while (l <= r):
          m = int(l + (r - l) / 2)
          if (arr[m] > k):
              leftGreater = m
              r = m - 1
          else:
              l = m + 1
      return leftGreater
  
  
  def findavg(y):
      s = 0
      for t in y:
          s += t
      k = s / len(y)
      return k
  
  
  def maxPrimeFactors(n):
      maxPrime = -1
      while n % 2 == 0:
          maxPrime = 2
          n >>= 1
  
      for i in range(3, int(math.sqrt(n)) + 1, 2):
          while n % i == 0:
              maxPrime = i
              n = n / i
      if n > 2:
          maxPrime = n
  
      return int(maxPrime)
  
  
  def decimalToBinary(N):
      # To store the binary number
      B_Number = 0
      cnt = 0
      while (N != 0):
          rem = N % 2
          c = pow(10, cnt)
          B_Number += rem * c
          N //= 2
  
          # Count used to store exponent value
          cnt += 1
  
      return B_Number
  
  
  def binaryToDecimal(n):
      num = n
      dec_value = 0
  
      # Initializing base
      # value to 1, i.e 2 ^ 0
      base1 = 1
  
      len1 = len(num)
      for i in range(len1 - 1, -1, -1):
          if (num[i] == '1'):
              dec_value += base1
          base1 = base1 * 2
  
      return dec_value
  
  
  def binarySearch(arr, l, r, x):
      # Check base case
      if r >= l:
  
          mid = l + (r - l) // 2
  
          # If element is present at the middle itself
          if arr[mid] == x:
              return mid
  
          # If element is smaller than mid, then it
          # can only be present in left subarray
          elif arr[mid] > x:
              return binarySearch(arr, l, mid - 1, x)
  
          # Else the element can only be present
          # in right subarray
          else:
              return binarySearch(arr, mid + 1, r, x)
  
      else:
          # Element is not present in the array
          return -1
  
  
  def mergeSort(arr):
      if len(arr) > 1:
  
          # Finding the mid of the array
          mid = len(arr) // 2
  
          # Dividing the array elements
          L = arr[:mid]
  
          # into 2 halves
          R = arr[mid:]
  
          # Sorting the first half
          mergeSort(L)
  
          # Sorting the second half
          mergeSort(R)
  
          i = j = k = 0
  
          # Copy data to temp arrays L[] and R[]
          while i < len(L) and j < len(R):
              if L[i] < R[j]:
                  arr[k] = L[i]
                  i += 1
              else:
                  arr[k] = R[j]
                  j += 1
              k += 1
  
          # Checking if any element was left
          while i < len(L):
              arr[k] = L[i]
              i += 1
              k += 1
  
          while j < len(R):
              arr[k] = R[j]
              j += 1
              k += 1
  
  
  def mergeSort(arr):
      if len(arr) > 1:
  
          # Finding the mid of the array
          mid = len(arr) // 2
  
          # Dividing the array elements
          L = arr[:mid]
  
          # into 2 halves
          R = arr[mid:]
  
          # Sorting the first half
          mergeSort(L)
  
          # Sorting the second half
          mergeSort(R)
  
          i = j = k = 0
  
          # Copy data to temp arrays L[] and R[]
          while i < len(L) and j < len(R):
              if L[i] < R[j]:
                  arr[k] = L[i]
                  i += 1
              else:
                  arr[k] = R[j]
                  j += 1
              k += 1
  
          # Checking if any element was left
          while i < len(L):
              arr[k] = L[i]
              i += 1
              k += 1
  
          while j < len(R):
              arr[k] = R[j]
              j += 1
              k += 1
  
  
  # Python program for implementation of MergeSort
  
  # Merges two subarrays of arr[].
  # First subarray is arr[l..m]
  # Second subarray is arr[m+1..r]
  def merge(arr, l, m, r):
      n1 = m - l + 1
      n2 = r - m
  
      # create temp arrays
      L = [0] * (n1)
      R = [0] * (n2)
  
      # Copy data to temp arrays L[] and R[]
      for i in range(0, n1):
          L[i] = arr[l + i]
  
      for j in range(0, n2):
          R[j] = arr[m + 1 + j]
  
      # Merge the temp arrays back into arr[l..r]
      i = 0  # Initial index of first subarray
      j = 0  # Initial index of second subarray
      k = l  # Initial index of merged subarray
  
      while i < n1 and j < n2:
          if L[i] <= R[j]:
              arr[k] = L[i]
              i += 1
          else:
              arr[k] = R[j]
              j += 1
          k += 1
  
      # Copy the remaining elements of L[], if there
      # are any
      while i < n1:
          arr[k] = L[i]
          i += 1
          k += 1
  
      # Copy the remaining elements of R[], if there
      # are any
      while j < n2:
          arr[k] = R[j]
          j += 1
          k += 1
  
  
  # l is for left index and r is right index of the
  # sub-array of arr to be sorted
  def mergeSort(arr, l, r):
      if l < r:
          # Same as (l+r)//2, but avoids overflow for
          # large l and h
          m = (l + (r - 1)) // 2
  
          # Sort first and second halves
          mergeSort(arr, l, m)
          mergeSort(arr, m + 1, r)
          merge(arr, l, m, r)
  
  
  def gcd(a, b):
      if a == 0:
          return b
  
      return gcd(b % a, a)
  for _ in range(int(input())):
      n=int(input())
      y=list(map(int,input().split()))
      if n==1:
          print(y[0])
      else:
          a=y[0]
          for t in range(1,len(y)):
              a=a&y[t]
          print(a)
  
  