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\leq i \leq r-l$), replace $a_{l+i}$ with $a_{l+i} \,\&\, a_{r-i}$ at the same time, where $\&$ denotes the bitwise AND operation . 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 \le t \le 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 \le n \le 100$) — the length of the sequence.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$).


-----Output-----

For each test case, print one integer — the minimal value of the maximum value in the sequence.


-----Examples-----

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$.

Difficulty: EASY
Tags: Bit manipulation

Mathematics

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(n, arr):
	res = arr[0]
	for i in range(1, len(arr)):
		res &= arr[i]
	return res
n = inp()
arr = []
for _ in range(n):
	print(solve(inp(), inlt()))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	idx = l.index(max(l))
	for i in range(n):
		for j in range(n):
			if l[i] != l[j]:
				l[i] = min(l[i] & l[j], l[j])
	print(l[idx])


N = int(input())
for test in range(N):
	n = int(input())
	alpha = list(map(int, input().split()))
	ans = alpha[0]
	for i in alpha:
		ans = ans & i
	print(ans)


count = int(input())
for _ in range(count):
	number = int(input())
	li1 = input().split()
	li2 = [int(i) for i in li1]
	d = max(li2)
	for i in li2:
		d = d & i
	print(d)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = a[0]
		for i in a:
			ans = ans & i
		print(ans)
main()


t = int(input())
for kkk in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	k = a[0]
	for i in range(1, n):
		k &= a[i]
	print(k)


test = int(input())
for _ in range(test):
	n = int(input())
	alist = list(map(int, input().split()))
	ans = alist[0]
	for i in alist:
		ans = ans & i
	print(ans)


import sys, copy
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	l = inlt()
	for i in range(len(l) - 1):
		l[i] = l[i] & l[i + 1]
		l[i + 1] = l[i]
	print(min(l))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = arr[0]
	for i in range(1, len(arr)):
		res &= arr[i]
	print(res)


def moc_a_math(arr):
	res = arr[0]
	for val in arr:
		res = res & val
	return res
for _ in range(int(input())):
	n = input()
	arr = list(map(int, input().split()))
	print(moc_a_math(arr))


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
T = int(input())
while T:
	T -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ans = a[0]
	for el in a:
		ans = ans & el
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = a[0]
	for i in range(1, n):
		ans = ans & a[i]
	print(ans)


t = int(input())
for tests in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	Min = a[0]
	for i in range(n):
		Min = Min & a[i]
	print(Min)


t = int(input())
for z in range(t):
	n = int(input())
	a = input().split(' ')
	res = (1 << 31) - 1
	for i in range(n):
		a[i] = int(a[i])
		res &= a[i]
	print(res)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	m1 = a[0]
	for i in range(1, n):
		m1 &= a[i]
	print(m1)
	t -= 1


test_cases = int(input())
for _ in range(test_cases):
	length = int(input())
	integers = [int(n) for n in input().split()]
	s = [integers[i] & integers[-1 - i] for i in range(len(integers))]
	c = s[0]
	if len(s) > 1:
		for i in range(1, len(s)):
			c &= s[i]
	print(c)


n = int(input())
for i in range(n):
	size = int(input())
	li = list(map(int, input().split()))
	res = li[0]
	for i in range(1, size):
		res = res & li[i]
	print(res)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(n):
		ans &= l[i]
	print(ans)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for j in range(1, n):
		ans &= arr[j]
	print(ans)


import math
from collections import Counter, defaultdict
import sys
mod = 10 ** 9 + 7
input = sys.stdin.readline
readInt = lambda : int(input().strip())
readfloat = lambda : float(input().strip())
readStr = lambda : input().strip()
intList = lambda : list(map(int, input().strip().split()))
intMap = lambda : map(int, input().strip().split())
floatList = lambda : list(map(float, input().strip().split()))
floatMap = lambda : map(float, input().strip().split())
strList = lambda : list(input().strip().split())

def print(*args, end='\n', sep=' '):
	for i in args:
		sys.stdout.write(str(i))
		sys.stdout.write(sep)
	sys.stdout.write(end)

def solve():
	res = max(arr)
	brr = [0] * 32
	for i in arr:
		for j in range(32):
			if i & 1 << j:
				brr[j] += 1
	res = []
	for i in brr:
		if i == n:
			res.append('1')
		else:
			res.append('0')
	return int(''.join(res[::-1]), 2)
for _ in range(readInt()):
	n = readInt()
	arr = intList()
	print(solve())


for _ in range(int(input())):
	n = int(input())
	lst = [int(el) for el in input().split()]
	ans = lst[0]
	for el in lst[1:]:
		ans &= el
	print(ans)


import sys
input = sys.stdin.readline
print = sys.stdout.write
import math
import functools

def get():
	return input().split()

def getint():
	return int(input())

def getints():
	return map(int, input().split())
for _ in range(getint()):
	n = getint()
	a = list(getints())
	x = -1
	for i in a:
		x = x & i
	print(f'{x}\n')


import math, sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
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 minp():
	return map(int, sys.stdin.readline().rstrip().split())

def linp():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def inp():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))

def yes():
	print('YES')

def no():
	print('NO')
for _ in range(inp()):
	n = inp()
	a = linp()
	res = a[0]
	for i in a[1:]:
		res &= i
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	res = lst[0]
	j = 1
	while j < len(lst):
		res = res & lst[j]
		j += 1
	print(res)


def main():
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		array = [int(a) for a in input().split()]
		ans = array[0]
		for i in range(1, n):
			ans &= array[i]
		print(ans)
main()


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for num in arr:
		ans &= num
	print(ans)


from collections import defaultdict
from itertools import permutations
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(10 ** 6)
input = stdin.readline
cout = stdout.write
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = a[0]
	for j in range(1, n):
		ans = ans & a[j]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	assert len(a) == n
	r = a[0]
	for i in a:
		r &= i
	print(r)


tt = int(input())
while tt > 0:
	n = int(input())
	inp = input().split(' ')
	ans = int(inp[0])
	for i in inp:
		ans = ans & int(i)
		n -= 1
	print(ans)
	tt -= 1


for _ in range(int(input())):
	length = int(input())
	array = list(map(int, input().split()))
	index_max = array.index(max(array))
	for i in array:
		array[index_max] = i & array[index_max]
	print(array[index_max])


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	m = min(arr)
	while True:
		arr = [x & m for x in arr]
		arr_m = min(arr)
		if min(arr) == m:
			break
		else:
			m = arr_m
	print(m)


t = int(input())
while t > 0:
	n = int(input())
	nums = list(map(int, input().split()))
	ans = nums[0]
	for num in nums:
		ans = ans & num
	print(ans)
	t -= 1


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = a[0]
	for i in range(n):
		ans &= a[i]
	ANS.append(str(ans))
print('\n'.join(ANS))


for t in range(int(input())):
	n = int(input())
	L = [int(x) for x in input().split()]
	x = L[0]
	for i in range(1, n):
		x = x & L[i]
	print(x)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = l[0]
	for i in l[1:]:
		c = c & i
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())]
	bits = [list(bin(l[i])[2:]) for i in range(n)]
	max_len = max((len(bits[i]) for i in range(n)))
	for i in range(n):
		bits[i] = [0] * (max_len - len(bits[i])) + bits[i]
	result = ''
	for i in range(max_len):
		flag = True
		s = set()
		for j in range(n):
			s.add(bits[j][i])
		if len(s) > 1:
			result += '0'
		else:
			result += bits[0][i]
	print(int(result, 2))


import sys, math, bisect, heapq
from collections import deque, defaultdict
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	ans = A[0]
	for i in range(n):
		ans = ans & A[i]
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
mod = 1000000007
MOD = mod
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False
t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(get_ints())
	ans = arr[0]
	for i in arr[1:]:
		ans = ans & i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = a[0]
	for j in a:
		ans = ans & j
	print(ans)


import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = A[0]
	for i in range(N):
		B &= A[i]
	print(B)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = a[0]
	for i in a:
		s = s & i
	print(s)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def solve(N, A):
	v = A[0]
	for a in A:
		v &= a
	return v
T0 = int(input())
for _ in range(T0):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve(N, A))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = l[0]
	for k in range(1, len(l)):
		x &= l[k]
	print(x)


import math
_ = 1
_ = int(input())
while _ > 0:
	_ -= 1
	n = int(input())
	l = list(map(int, input().split()))
	c = l[0]
	for x in range(1, n):
		c = c & l[x]
	print(c)


def main():
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

	def ncr(n, r):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % mod
			den = den * (i + 1) % mod
		return num * pow(den, mod - 2, mod) % mod

	def solve(n, arr):
		AND = arr[0]
		for i in range(n):
			AND = AND & arr[i]
		return AND
		pass
	t = int(input())
	ans = []
	for _ in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		ans.append(solve(n, arr))
	for answer in ans:
		print(answer)
import sys, threading
import bisect
import math
import itertools
from sys import stdout
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


n = int(input())
for i in range(0, n):
	v = int(input())
	a = input().split()
	ans = int(a[0])
	for j in range(1, v):
		ans = ans & int(a[j])
	print(ans)


import math

def intlist():
	return [int(i) for i in input().split(' ')]

def solve():
	n = int(input())
	res = -1
	l = intlist()
	for i in l:
		res = res & i
	return res
t = input()
for tt in range(int(t)):
	print(solve())


t = int(input())
for tst in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = arr[0]
	for item in arr[1:]:
		ans &= item
	print(ans)


n = int(input())
for i in range(n):
	m = int(input())
	k = list(map(int, input().split()))
	x = k[0]
	for j in range(len(k)):
		x = x & k[j]
	print(x)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = tuple(map(int, input().split()))
	ans = arr[0]
	for x in arr:
		ans = ans & x
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = eval('&'.join(input().split()))
	print(a)


tC = int(input())
for __ in range(tC):
	N = int(input())
	A = list(map(int, input().split()))
	_and = A[0]
	for X in A:
		_and &= X
	print(_and)


t = int(input())
for i in range(t):
	binsry = [0 for i in range(35)]
	n = int(input())
	lis = [int(x) for x in input().split()]
	for j in range(len(binsry)):
		for k in range(len(lis)):
			if lis[k] & 1:
				binsry[j] += 1
			lis[k] >>= 1
	result = ''
	for j in range(len(binsry)):
		if binsry[j] == n:
			result += '1'
		else:
			result += '0'
	po = 1
	answer = 0
	for items in result:
		if items == '1':
			answer += po
		po *= 2
	print(answer)


import sys
import os
from math import *
from functools import reduce

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		print(reduce(lambda x, y: x & y, l))
main()


def int_input():
	a = int(input())
	return a

def int_list_input():
	a = list(map(int, input().split()))
	return a

def solve():
	n = int_input()
	arr = int_list_input()
	ans = arr[0]
	for i in arr:
		ans = ans & i
	print(ans)
for _ in range(int(input())):
	solve()


import math
import sys
input = sys.stdin.buffer.readline
import string
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
MOD = 1000000007

def preprocess():
	pass

def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	res = lst[0]
	for i in range(1, n):
		res &= lst[i]
	print(res)
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	x = A[0]
	for i in range(len(A)):
		x &= A[i]
	print(x)


for i in range(int(input())):
	x = input()
	arr = list(map(int, input().split()))
	x = arr[0]
	for j in arr:
		x = x & j
	print(x)


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	m = ls[0]
	a = 0
	for i in range(1, n):
		m = m & ls[i]
	print(m)


def solve():
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = 2 ** 32 - 1
	for i in arr:
		s &= i
	print(s)
t = int(input())
for i in range(t):
	solve()


def solve():
	n = int(input())
	A = list(map(int, input().split(' ')))
	res = (1 << 31) - 1
	for a in A:
		res &= a
	print(res)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	ans = A[0]
	for i in range(1, N):
		ans &= A[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	seq = list(map(int, input().split()))
	x = seq[0]
	for i in seq[1:]:
		x = x & i
	print(x)


for s in [*open(0)][2::2]:
	l = [*map(int, s.split())]
	a = min(l)
	for x in l:
		a = a & x
	print(a)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))[:n]
	while True:
		if len(set(ar)) == 1:
			break
		else:
			k = min(ar)
			for i in range(n):
				ar[i] = ar[i] & k
	print(ar[0])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = a[0]
	a.pop(0)
	for i in a:
		ans = ans & i
	print(ans)


num = int(input())
for i in range(num):
	n = int(input())
	print(eval(input().replace(' ', '&')))


t = int(input())
min = 0
for i in range(t):
	n = int(input())
	seq = list(map(int, input().split()))
	min = seq[0]
	for j in range(1, n):
		min = min & seq[j]
	print(min)


for t in range(int(input())):
	n = int(input())
	my_list = list(map(int, input().split()))
	x = my_list[0]
	for i in range(1, n):
		x = x & my_list[i]
	print(x)


def solve(count, list_):
	ans = list_[0]
	for el in list_:
		ans &= el
	return ans
for _ in range(int(input())):
	n = int(input())
	mas = list(map(int, input().split()))
	print(solve(n, mas))


for i in range(int(input())):
	numero = int(input())
	lista = list(map(int, input().split()))
	reset = lista[0]
	for j in lista:
		reset &= j
	print(reset)


for Pythonic__Python in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = x[0]
	for i in x:
		ans = ans & i
	print(ans)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def sout(v):
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def sieve(n):
	primes = []
	least_prime_divs = [0] * (n + 1)
	for i in range(2, n + 1):
		if not least_prime_divs[i]:
			least_prime_divs[i] = i
			primes.append(i)
		for p in primes:
			if i * p > n or p > least_prime_divs[i]:
				break
			least_prime_divs[i * p] = p
	return primes
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	mx = -1
	d = {}
	for i in a:
		for j in range(34):
			if i & 1 << j:
				mx = max(mx, j)
			else:
				d[j] = True
	ans = 0
	for i in range(mx + 1):
		if i not in d:
			ans += pow(2, i)
	print(ans)


test = eval(input())
for i in range(test):
	n = eval(input())
	numbers = list(map(int, input().split()))
	start = numbers[0]
	for i in range(1, n):
		start = start & numbers[i]
	print(start)


n = int(input())
for i in range(n):
	m = int(input())
	lst = list(map(int, input().split()))
	res = lst[0]
	for j in lst[1:]:
		res &= j
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = a[0]
	for i in range(1, n):
		ans &= a[i]
	print(ans)


for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	a = y[0]
	for i in range(1, x):
		a = a & y[i]
	print(a)


for _ in range(int(input())):
	n = int(input())
	A = sorted(list(map(int, input().split())))
	A = A[::-1]
	if n == 1:
		print(A[0])
	elif n == 2:
		if A[0] & A[1] < max(A):
			print(A[0] & A[1])
		else:
			print(max(A))
	else:
		s = A[0] & A[1]
		for i in range(2, n):
			s = s & A[i]
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	mini = l[0]
	for j in range(1, n):
		mini = mini & l[j]
	print(mini)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())
for _ in range(ii()):
	n = ii()
	l = li()
	ans = l[0]
	for i in l[1:]:
		ans &= i
	print(ans)


import math
from itertools import product
from math import ceil, gcd, sqrt
import string
from decimal import Decimal

def binary_table(string_with_all_characters, length_to_make):
	return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)]

def binary_table_set(string_with_all_characters, length_to_make):
	return {''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)}

def all_possible_substrings(string, length):
	return [string[i:j + 1] for i in range(length) for j in range(i, length)]

def all_possible_substrings_set(string, length):
	return {string[i:j + 1] for i in range(length) for j in range(i, length)}

def number_of_substrings(length):
	return int(length * (length + 1) / 2)

def find_and(arr):
	ans = arr[0]
	for i in range(1, len(arr)):
		ans = ans & arr[i]
	return ans

def solve():
	length_of_array = int(input())
	array = list(map(int, input().split()))
	print(find_and(array))
for enumeration in range(int(input())):
	solve()


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)
import os
import sys
from io import BytesIO, IOBase
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 RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
for _ in range(N()):
	n = N()
	a = RLL()
	x = a[0]
	for i in a:
		x &= i
	print(x)


import math
import heapq
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	n = I()
	l = L()
	p = 0
	cur = max(l)
	while max(l) != min(l):
		p = cur
		i = min(l.index(max(l)), l.index(min(l)))
		j = max(l.index(max(l)), l.index(min(l)))
		for k in range(j - i + 1):
			l[i + k] = l[j - k] & l[i + k]
		cur = max(l)
	print(max(l))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	x = arr[0]
	for i in range(1, len(arr)):
		x = x & arr[i]
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	_min = min(nums)
	ans = _min
	for num in nums:
		ans &= num
	print(ans)


from functools import reduce
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = reduce(lambda a, b: a & b, a)
	ans.append(str(s))
print('\n'.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	la = lis[0]
	for i in range(1, n):
		la = la & lis[i]
	print(la)


import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log, comb, perm, factorial
mod = int(1000000000.0 + 7)
inf = int(1e+20)
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
ii = lambda : int(input())
t = ii()
for _ in range(t):
	n = ii()
	arr = [int(i) for i in input().split()]
	res = 0
	for (i, a) in enumerate(arr):
		if i == 0:
			res = a
		else:
			res &= a
	print(res)


a = int(input())
while a > 0:
	a -= 1
	n = int(input())
	print(eval(input().replace(' ', '&')))


for _ in range(0, int(input())):
	input()
	v = list(map(int, input().split()))
	t = v[0]
	for i in v[1:]:
		t &= i
	print(t)


import sys, os
from math import sqrt
from collections import defaultdict
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	x = A[0]
	for i in range(1, n):
		x = x & A[i]
	print(x)


for tc in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	num = a[0]
	for vv in a[1:]:
		num &= vv
	print(num)


import sys
import math
import re
from collections import Counter
from bisect import bisect_left

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far
t = int(input())
mod = pow(10, 9) + 7
while t > 0:
	n = int(input())
	l = [int(x) for x in input().split()]
	ans = l[0]
	for i in range(1, n):
		ans = ans & l[i]
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	lst = [*map(int, input().split())]
	res = -1
	for i in lst:
		res = res & i
	print(res)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes
from collections import Counter

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small
	return ans

def main():
	mod = 1000000007
	mod1 = 998244353
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	pow2 = [1]
	for i in range(300005):
		pow2.append(pow2[-1] * 2 % mod1)
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = ria()
		cur = a[0]
		for i in range(1, n):
			cur = cur & a[i]
		wi(cur)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for t1 in range(t):
	n = int(input())
	f = input().split()
	h = [int(_) for _ in f]
	ans = h[0]
	for i in range(1, n):
		ans &= h[i]
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split(' ')[:n]))
	c = l[0]
	for i in range(len(l)):
		c = c & l[i]
	print(c)
	t -= 1


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	ans = a[0]
	for i in a:
		ans &= i
	print(ans)


import os, sys
input = lambda : sys.stdin.buffer.readline().rstrip(b'\r\n')

def dbp(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)
a_str = lambda : input().decode('ascii')
get_int_list = lambda : [int(x) for x in input().split()]
join_str = lambda l, ch=' ': ch.join((str(x) for x in l))

def do_thing():
	n = int(input())
	alist = get_int_list()
	ans = alist[0]
	for i in range(n):
		ans &= alist[i]
	return ans

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


from collections import Counter
from itertools import accumulate, product, groupby
import operator
import math
from functools import reduce

def solve():
	n = int(input())
	arr = [int(char) for char in input().split()]
	return reduce(operator.and_, arr)
for _ in range(int(input())):
	print(solve())


import math
import bisect

def printf(str):
	print(str, end=' ')
test_case = int(input())
t = 0
while t < test_case:
	arr = []
	n = int(input())
	inpt = input().split()
	for i in range(n):
		arr.append(int(inpt[i]))
	x = arr[0]
	for i in range(1, n):
		x = x & arr[i]
	print(x)
	t += 1


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = max(l)
	for i in range(n):
		x = x & l[i]
	print(x)


import os
import sys
from io import BytesIO, IOBase
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')
from itertools import permutations
from collections import *
from collections import deque
from operator import itemgetter, attrgetter
from decimal import *
import bisect
import math
import heapq as hq
MOD = 10 ** 9 + 7

def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True

def pow(a, b, m):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % m
		b //= 2
		a = a * a % m
	return ans

def ispalindrome(s):
	if s[:] == s[::-1]:
		return 1
	return 0
dp = []
limit = []
v = []

def dpdfs(u, t=-1):
	dp[0][u] = 0
	dp[1][u] = 0
	for i in v[u]:
		if i == t:
			continue
		if dp[1][i] == -1:
			dpdfs(i, u)
		dp[0][u] += max(abs(limit[0][u] - limit[1][i]) + dp[1][i], abs(limit[0][u] - limit[0][i]) + dp[0][i])
		dp[1][u] += max(abs(limit[1][u] - limit[1][i]) + dp[1][i], abs(limit[1][u] - limit[0][i]) + dp[0][i])
vis = []
f = 0

def dfs(i):
	vis[i] = 1
	act[i] = 1
	for j in v[i]:
		if act[j]:
			f = 1
			return -1
		if vis[j] == 0:
			if dfs(j) == -1:
				return -1
	act[i] = 0
	ans.append(i)
	return 0
from queue import PriorityQueue

def z_algorithm(s):
	res = [0] * len(s)
	res[0] = len(s)
	(i, j) = (1, 0)
	while i < len(s):
		while i + j < len(s) and s[j] == s[i + j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < len(s) and k + res[k] < j:
			res[i + k] = res[k]
			k += 1
		(i, j) = (i + k, j - k)
	return res

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / math.gcd(int(a), int(b))

def gcdExtended(a, b):
	if a == 0:
		return (b, 0, 1)
	(gcd, x1, y1) = gcdExtended(b % a, a)
	x = y1 - b // a * x1
	y = x1
	return (gcd, x, y)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, n):
		ans = ans & l[i]
	print(ans)


t = int(input())
for testcase in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	minimal = arr[0]
	for k in range(1, n):
		minimal &= arr[k]
	print(minimal)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	res = a[0]
	for i in range(1, len(a)):
		res = res & a[i]
	print(res)


for t in range(int(input())):
	n = int(input())
	a = input()
	print(eval(a.replace(' ', '&')))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		arr = get_list()
		ans = arr[0]
		for i in range(1, n, 1):
			ans = ans & arr[i]
		get_print_int(ans)
solve()


for _ in [0] * int(input()):
	input()
	r = [*map(int, input().split())]
	s = r[0]
	for i in r[1:]:
		s &= i
	print(s)


for _ in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	l.sort()
	a1 = l[0]
	for i in range(1, a):
		a1 = a1 & l[i]
	print(a1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	for i in a:
		x &= i
	print(x)


import traceback
import os
import sys
from io import BytesIO, IOBase
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 = IOWrapper(sys.stdin)
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r, mod=10 ** 9 + 7):
	num = den = 1
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)

def put(a):
	return ' '.join(map(str, a))
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	((N,), a) = getinps('il il')
	ans = a[0]
	for x in a:
		ans &= x
	return ans
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		ans = str(ans)
		answers.append(ans)
	print('\n'.join(answers))
except Exception as e:
	print(e)
	traceback.print_exc()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	z = l[0]
	for x in range(1, n):
		z = z & l[x]
	print(z)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in l[1:]:
		ans &= i
	print(ans)


import random
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = int(1000000000.0 + 7)

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return -1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	prvs = [i for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			prvs[i * j] = j
			if i % j == 0:
				break
	return (primes, prvs)

def lower_ord(c: str) -> int:
	return ord(c) - 97

def upper_ord(c: str) -> int:
	return ord(c) - 65

def read_list():
	return [int(i) for i in input().split()]

def read_int():
	s = input().split()
	if len(s) == 1:
		return int(s[0])
	else:
		return map(int, s)

def ask(s):
	print(f'? {s}', flush=True)

def answer(s):
	print(f'{s}', flush=True)
import functools
import itertools
from fractions import Fraction
import random

def lowbit(x):
	return -x & x

def pref(x):
	return x * (x + 1) >> 1

def cum(sx, mx):
	return (sx + mx) * (mx - sx + 1) >> 1

def solve():
	n = read_int()
	li = read_list()
	ans = li[0]
	for i in li:
		ans &= i
	print(ans)
T = int(input())
for ti in range(T):
	solve()


import os, sys
import math
from io import BytesIO, IOBase
from collections import Counter
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):
	B_Number = 0
	cnt = 0
	while N != 0:
		rem = N % 2
		c = pow(10, cnt)
		B_Number += rem * c
		N //= 2
		cnt += 1
	return B_Number

def binaryToDecimal(n):
	num = n
	dec_value = 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):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		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
		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:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		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
		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 merge(arr, l, m, r):
	n1 = m - l + 1
	n2 = r - m
	L = [0] * n1
	R = [0] * n2
	for i in range(0, n1):
		L[i] = arr[l + i]
	for j in range(0, n2):
		R[j] = arr[m + 1 + j]
	i = 0
	j = 0
	k = l
	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
	while i < n1:
		arr[k] = L[i]
		i += 1
		k += 1
	while j < n2:
		arr[k] = R[j]
		j += 1
		k += 1

def mergeSort(arr, l, r):
	if l < r:
		m = (l + (r - 1)) // 2
		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)


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	s = l[0]
	for i in range(1, n):
		s = s & l[i]
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	ans = ~0
	for el in arr:
		ans &= el
	print(ans)


import math

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def prime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
	return prime_flag
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, n):
		ans = ans & l[i]
	print(ans)
	t = t - 1


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	mn = l[0]
	for e in l:
		mn = mn & e
	print(mn)
t = int(input())
for _ in range(t):
	solve()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	res = arr[0]
	for i in range(len(arr)):
		res = res & arr[i]
	return res
t = int(input())
while t:
	print(solve())
	t -= 1


from collections import Counter
from math import *
import sys
import bisect as bs
from math import *
mod = 1000000007

def help(arr, i, j):
	while i < j:
		arr[i] = arr[i] & arr[j]
		arr[j] = arr[j] & arr[i]
		i += 1
		j -= 1

def pro(arr):
	n = len(arr)
	for i in range(2 * n):
		ind = 0
		maxi = -1
		for j in range(n):
			if maxi < arr[j]:
				maxi = arr[j]
				ind = j
		mini = arr[ind]
		ind2 = 0
		for j in range(n):
			if mini > arr[ind] & arr[j]:
				mini = arr[ind] & arr[j]
				ind2 = j
		help(arr, min(ind, ind2), max(ind, ind2))
	print(max(arr))
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pro(arr)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = c[0]
	for i in range(1, b):
		d = d & c[i]
	print(d)


from math import ceil, log, floor
from collections import defaultdict
import sys
import os.path
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')

def MI():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(list(map(int, input().split())))
	m = a[0]
	for i in range(n):
		m = a[i] & m
	print(m)


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()][:n]
	minimum = a[0]
	for i in a:
		minimum = minimum & i
	print(minimum)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	sml = lst[0]
	for i in lst:
		sml = sml & i
	print(sml)


import math

def main():
	t = int(input())
	for _ in range(t):
		print(case())

def case():
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	for num in a[1:]:
		x = x & num
	return x
main()


from functools import reduce
t = int(input())
for _ in range(t):
	n = input()
	print(reduce(lambda a, b: a & b, [int(i) for i in input().split(' ')]))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	x = arr[0]
	for i in range(len(arr)):
		x = x & arr[i]
	print(x)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		flag = True
		while flag:
			flag = False
			for i in range(1, n):
				ae = a[i] & a[i - 1]
				a[i] = ae
				a[i - 1] = ae
			for i in range(1, n):
				if a[i] != a[i - 1]:
					flag = True
					break
		print(a[0])
main()


def solution():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		x = a[0]
		for i in a:
			x = x & i
		print(x)
solution()


import functools
m = int(input())
for _ in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	print(functools.reduce(lambda a, b: a & b, a, a[0]))


from math import ceil, floor
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, len(l)):
		ans &= l[i]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	x = A[0]
	for i in range(1, n):
		x &= A[i]
	print(x)


for _ in range(int(input())):
	input()
	print(eval(input().replace(' ', '&')))


def findAns(arr):
	res = arr[0]
	for i in range(1, len(arr)):
		res = res & arr[i]
	return res
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	print(findAns(arr))


for pratyush in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = a[0]
	for i in range(1, n):
		f &= a[i]
	print(f)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	aand = a[0]
	for i in a:
		aand &= i
	print(aand)


def f(arr, N):
	ans = arr[0]
	for i in range(1, N):
		ans = ans & arr[i]
	return ans
t = int(input())
for _ in range(t):
	N = int(input())
	arr = list(map(int, input().split()))
	print(f(arr, N))


for p in range(int(input())):
	n = int(input())
	a = input().split(' ')
	k = 0
	for i in range(n):
		if i == 0:
			k = int(a[i]) & int(a[i])
		else:
			k = k & int(a[i])
	print(k)


for x in range(int(input())):
	n = int(input())
	sq = [int(i) for i in input().split()]
	res = sq[0]
	for i in range(1, n):
		res &= sq[i]
	print(res)


import functools as _functools
import operator as _operator
import sys as _sys

def _main():
	[tests_n] = _read_ints()
	for i_test in range(tests_n):
		[a_n] = _read_ints()
		a_seq = tuple(_read_ints())
		result = f(a_seq)
		print(result)

def f(seq):
	seq = tuple(seq)
	assert seq
	return _functools.reduce(_operator.and_, seq, max(seq))

def _read_ints():
	return map(int, _read_string().split())

def _read_string():
	return _sys.stdin.readline()[:-1]
_main()


import math
from sys import stdin
from collections import Counter
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	m = a[0]
	for i in range(1, n):
		m = m & a[i]
	print(m)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(n):
		ans &= l[i]
	print(ans)


ans = 0
for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().split(' ')))
	res = y[0]
	for i in y:
		res = res & i
	print(res)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	result = data[0]
	for i in data[1:]:
		result = result & i
	print(result)


for s in [*open(0)][2::2]:
	print(eval(s.replace(' ', '&')))


t = int(input())
for _ in range(t):
	n = int(input())
	liczby = list(map(int, input().split()))
	if n > 2:
		liczby.sort()
		while liczby[0] != liczby[n - 1]:
			for x in range(n):
				for y in range(n):
					liczby[x] = liczby[x] & liczby[y]
					if liczby[x] == 0:
						wynik = 0
						break
		else:
			wynik = liczby[0]
	else:
		wynik = max(liczby) & min(liczby)
	print(wynik)


def getlistint():
	return list(map(int, stdin.readline().split()))

def getmapint():
	return map(int, stdin.readline().split())

def getliststr():
	return list(stdin.readline().split())

def getint():
	return int(stdin.readline().strip())

def getstr():
	return stdin.readline().strip()

def pr(s):
	stdout.write(str(s) + '\n')

def prlist(l):
	stdout.write(' '.join(list(map(str, l))) + '\n')
from sys import stdin, stdout
for _ in range(getint()):
	n = getint()
	a = getlistint()
	x = a[0]
	for i in range(1, n):
		x = x & a[i]
	pr(x)


import os
import sys
from io import BytesIO, IOBase
_print = print
BUFSIZE = 8192

def dbg(*args, **kwargs):
	_print('\x1b[95m', end='')
	_print(*args, **kwargs)
	_print('\x1b[0m', end='')

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')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def reduce_and(iterable) -> int:
	result = (1 << 65) - 1
	for item in iterable:
		result &= item
	return result

def solve():
	inp()
	return reduce_and(mpint())

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1559/problem/0'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 2:
		dbg = lambda *args, **kwargs: ...
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG == 3:

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


from functools import reduce
import operator
for _ in range(int(input())):
	N = int(input())
	li = list(map(int, input().split()))
	print(reduce(operator.and_, li))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = arr[0]
	for num in arr:
		res &= num
	print(res)


t = int(input())
for q in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	ans = lst[0]
	for i in lst:
		ans = ans & i
	print(ans)


def conv(x):
	temp = bin(x)[2:]
	return [len(temp), temp]
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = arr[0]
	for j in range(1, n):
		res = res & arr[j]
	print(res)


TC = int(input())
while TC > 0:
	TC -= 1
	n = int(input())
	print(eval(input().replace(' ', '&')))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	res = a[0]
	for i in range(1, n):
		res &= a[i]
	print(res)
for _ in range(int(input())):
	solve()


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	li = list(map(int, input().split()))
	s = li[0]
	for i in range(n):
		s = s & li[i]
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	ans = nums[0]
	for num in nums:
		ans &= num
	print(ans)


for _ in range(int(input())):
	n = int(input())
	v = [int(x) for x in input().split(' ')]
	s = v[0]
	for i in range(n - 1):
		s = s & v[i + 1]
	print(s)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())
t = I()
for _ in range(t):
	n = I()
	a = LI()
	res = a[0]
	for i in a[1:]:
		res &= i
	print(res)


def solve(n, arr):
	while True:
		check = True
		for x in range(1, n):
			if arr[x] != arr[x - 1]:
				check = False
				arr[x] = arr[x - 1] = arr[x] & arr[x - 1]
		if check:
			print(arr[0])
			return
for _ in range(int(input())):
	solve(int(input()), list(map(int, input().split())))


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = A[0]
	for i in range(1, n):
		ans &= A[i]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[0]
	k = 0
	while k < len(a):
		b &= a[k]
		k += 1
	print(b)


for _ in range(int(input())):
	a = (1 << 31) - 1 + 0 * int(input())
	for i in map(int, input().split()):
		a &= i
	print(a)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = arr[0]
	for i in range(1, n):
		ans &= arr[i]
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	v = arr[0]
	for i in range(1, n):
		v &= arr[i]
	return v
for _ in range(int(input())):
	print(solve())


import sys, functools
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	print(functools.reduce(lambda a, b: a & b, arr))


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	ans = a[0]
	for i in range(n):
		ans &= a[i]
	print(ans)


import sys
for _ in range(int(input())):
	t = int(input())
	a = [int(x) for x in sys.stdin.readline().rstrip().split()]
	ans = a[0]
	for i in a:
		ans &= i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	answer = min(numbers)
	for j in range(n):
		answer &= numbers[j]
	print(answer)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	for i in range(1, n):
		a = a & l[i]
	print(a)
	t -= 1


t = int(input())
while t:
	k = int(input())
	arr = list(map(int, input().split()))
	if k == 1:
		print(arr[0])
	else:
		ans = arr[0]
		for i in arr:
			ans = ans & i
		print(ans)
	t -= 1


def getMin(arr, n):
	mele = max(arr)
	ele = arr[0]
	for i in range(n):
		ele &= arr[i]
	return mele & ele
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(getMin(arr, n))


from sys import stdin
from math import floor, ceil

def get_int():
	return int(stdin.readline())

def get_str():
	return stdin.readline()[:-1]

def get_int_list():
	return list(map(int, stdin.readline().split()))

def get_str_list():
	return list(map(str, stdin.readline().split()))

def solve():
	a = get_int()
	l = get_int_list()
	l = list(set(l))
	ans = l[0]
	for i in range(1, len(l)):
		ans = ans & l[i]
	print(ans)
testcase = True
if testcase == True:
	n = get_int()
	for _ in range(n):
		solve()
else:
	solve()


out = []

def mocha_math():
	n = int(input())
	a = list(map(int, input().split()))
	m1 = a[0]
	for i in range(1, n):
		m1 &= a[i]
	out.append(m1)
iter = int(input())
while iter > 0:
	mocha_math()
	iter -= 1
for x in range(0, len(out)):
	print(out[x])


def main():
	N = int(input())
	for _ in range(N):
		n = int(input())
		a_s = list(map(int, input().split()))
		ans = a_s[0]
		for a in a_s:
			ans &= a
		print(ans)
main()