You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator.
In total, there are $\frac{N(N+1)}{2}$ possible pairs $(l, r)$, i.e. $\frac{N(N+1)}{2}$ possible values of $\mathrm{OR}(l, r)$. Determine if all these values are pairwise distinct.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing the string "YES" if all values of $\mathrm{OR}(l, r)$ are pairwise distinct or "NO" otherwise (without quotes).

-----Constraints-----
- $1 \le T \le 300$
- $1 \le N \le 10^5$
- $0 \le A_i \le 10^{18}$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $3 \cdot 10^5$

-----Example Input-----
4
3
1 2 7
2
1 2
3
6 5 8
5
12 32 45 23 47

-----Example Output-----
NO
YES
YES
NO

-----Explanation-----
Example case 1: The values of $\mathrm{OR}(l, r)$ are $1, 2, 7, 3, 7, 7$ (corresponding to the contiguous subsequences $[1], [2], [7], [1,2], [2,7], [1,2,7]$ respectively). We can see that these values are not pairwise distinct.
Example case 2: The values of $\mathrm{OR}(l, r)$ are $1, 2, 3$ (corresponding to the contiguous subsequences $[1], [2], [1, 2]$ respectively) and they are pairwise distinct.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Mathematics

Complete search


Solutions:
t = int(input())
while t != 0:
	n = int(input())
	ls = list(map(int, input().split()))
	p = {0}
	res = set()
	for i in ls:
		p = {i | y for y in p} | {i}
		res |= p
	if len(res) == n * (n + 1) // 2:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	f = 1
	v1 = [-1]
	v2 = [-1]
	temp = 0
	for i in l:
		temp = temp | i
		if temp == v1[-1]:
			f = 0
			break
		v1.append(temp)
	if f == 0:
		print('NO')
		continue
	temp = 0
	for i in range(n - 1, -1, -1):
		temp = temp | l[i]
		if temp == v2[-1]:
			f = 0
			break
		v2.append(temp)
	if f == 0:
		print('NO')
	else:
		print('YES')
		v2.append(temp)


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	if n > 62:
		print('NO')
	else:
		v = []
		f = 0
		for i in range(n):
			x = ar[i]
			if ar[i] not in v:
				v.append(ar[i])
			else:
				f = 1
				break
			for j in range(i + 1, n):
				x |= ar[j]
				if x in v:
					f = 1
					break
				else:
					v.append(x)
			if f == 1:
				break
		if f == 1:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	to_add = a[0]
	f = 0
	for i in range(1, n):
		to_add = to_add | a[i]
		if to_add in a:
			f = 1
			break
		a.append(to_add)
	if f == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	tot = n * (n + 1) // 2
	ans = a.copy()
	to_add = 0
	if n > 62:
		print('NO')
		continue
	for i in range(n - 1):
		to_add = a[i]
		for j in range(i + 1, n):
			to_add = to_add | a[j]
			ans.append(to_add)
	if len(set(ans)) == tot:
		print('YES')
	else:
		print('NO')


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	if N > 62:
		ans.append('NO')
	else:
		D = {}
		flag = True
		for i in range(N):
			x = 0
			for j in range(i, N):
				x |= A[j]
				if x in D:
					flag = False
					break
				D[x] = True
			if not flag:
				break
		if flag:
			ans.append('YES')
		else:
			ans.append('NO')
for i in ans:
	print(i)


def answer():
	value = a[0]
	if n <= 60:
		all_ = set()
		for i in range(n):
			value = 0
			for j in range(i, n):
				value |= a[j]
				all_.add(value)
		if len(all_) == n * (n + 1) // 2:
			return 'YES'
	return 'NO'
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(answer())


def orthodox(a, n):
	vals = set()
	for i in range(n):
		orr = 0
		for j in range(i, n):
			orr |= a[j]
			if orr in vals:
				print('NO')
				return
			vals.add(orr)
	print('YES')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	orthodox(a, n)


T = int(input())
while T:
	N = int(input())
	A = list(map(int, input().split()))
	d = set()
	n = N * (N + 1) // 2
	if N > 60:
		print('NO')
	else:
		for i in range(N):
			ans = 0
			for j in range(i, N):
				ans = A[j] | ans
				d.add(ans)
		if len(d) == n:
			print('YES')
		else:
			print('NO')
	T -= 1


import numpy as np
t = int(input())
while t:
	n = int(input())
	li = [int(x) for x in input().split()]
	if n > 60:
		print('NO')
	else:
		l = [[0 for i in range(n)] for j in range(n)]
		for i in range(n):
			l[i][i] = li[i]
		for i in range(n - 1):
			j = 0
			for k in range(i + 1, n):
				l[j][k] = l[j][k - 1] | l[j + 1][k]
				li.append(l[j][k])
				j = j + 1
		p = np.array(li)
		if len(np.unique(p)) == len(li):
			print('YES')
		else:
			print('NO')
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	N = n * (n + 1) // 2
	d = set()
	if n > 60:
		print('NO')
	else:
		for i in range(n):
			ans = 0
			for j in range(i, n):
				ans = l[j] | ans
				d.add(ans)
		if len(d) == N:
			print('YES')
		else:
			print('NO')


from collections import Counter
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = dict()
	f = 0
	d = 0
	for i in range(n):
		for j in range(i + 1, n + 1):
			s = l[i:j]
			d += 1
			r = reduce(lambda x, y: x | y, s)
			a[r] = a.get(r, 0) + 1
			if a[r] != 1:
				f = 1
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


def ortho(n, m):
	res = set()
	tot = n * (n + 1) // 2
	pre = {0}
	for x in m:
		pre = {x | y for y in pre} | {x}
		res |= pre
	if len(res) == tot:
		return 'YES'
	return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	print(ortho(n, m))


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

def string_list():
	return list(map(str, input().split()))

def hetro_list():
	return list(input().split())

def main():
	visited = set()
	for l in range(n):
		prev = lst[l]
		for r in range(l, n):
			prev = prev | lst[r]
			if prev not in visited:
				visited.add(prev)
			else:
				print('NO')
				return
	else:
		print('YES')
t = int(input())
for _ in range(t):
	n = int(input())
	lst = integer_list()
	main()


def snek(a):
	r = set()
	p = {0}
	for i in a:
		p = {i | j for j in p} | {i}
		r |= p
	return len(r)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = snek(a)
	print('YES' if s == n * (n + 1) // 2 else 'NO')


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	f = 1
	for i in range(n):
		a = l[i]
		for j in range(i, n):
			a |= l[j]
			if a in s:
				print('NO')
				f = 0
				break
			s.add(a)
		if f == 0:
			break
	if f:
		print('YES')


import math
from sys import stdin
t = int(stdin.readline())
while t:
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	if n >= 61:
		print('NO')
	else:
		val_set = set()
		for i in range(0, n):
			or_val = 0
			for j in range(i, n):
				or_val = or_val | a[j]
				val_set.add(or_val)
		if len(val_set) == n * (n + 1) / 2:
			print('YES')
		else:
			print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 62:
		s = set()
		for i in range(n):
			c = 0
			for j in range(i, n):
				c = c | a[j]
				s.add(c)
		if len(s) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	s = set()
	if n > 60:
		print('NO')
	else:
		for i in range(n):
			ordd = 0
			for j in range(i, n):
				ordd = ordd | arr[j]
				s.add(ordd)
		if len(s) == n * (n + 1) / 2:
			print('YES')
		else:
			print('NO')


from collections import Counter
from functools import reduce
from operator import ior
for i in range(int(input())):
	_ = input()
	n = [int(i) for i in input().split()]
	if len(n) > 60:
		print('NO')
	else:
		now = []
		for i in range(len(n)):
			for j in range(i, len(n)):
				res = reduce(ior, n[i:j + 1])
				now.append(res)
		p = Counter(now).values()
		ans = 1
		for i in p:
			if i >= 2:
				ans = 0
		if ans:
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	o = l[0]
	ans = True
	for i in range(1, n):
		tmp = o | l[i]
		if tmp == o:
			ans = False
			break
		o = tmp
	if ans:
		o = l[-1]
		for i in range(n - 2, -1, -1):
			tmp = o | l[i]
			if tmp == o:
				ans = False
				break
			o = tmp
	if ans:
		print('YES')
	else:
		print('NO')


def orlr(i, j, l):
	temp = 0
	for k in range(j, j + i):
		temp = temp | l[k]
	return temp

def check(n, l):
	d = {}
	for i in range(n):
		for j in range(0, n - i):
			ans = orlr(i + 1, j, l)
			if d.get(ans, 0) == 0:
				d[ans] = 1
			else:
				print('NO')
				return
	print('YES')
	return
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(k) for k in input().split()]
	check(n, l)


def sub_lists(list1):
	sublist = []
	for i in range(len(list1) + 1):
		for j in range(i + 1, len(list1) + 1):
			sub = list1[i:j]
			sublist.append(sub)
	return sublist

def distinctORs(lst):
	ss = set()
	for i in range(len(lst)):
		iLst = lst[i]
		if len(iLst) == 1:
			ss.add(iLst[0])
		else:
			temOR = 0
			for j in range(len(iLst)):
				temOR |= iLst[j]
			ss.add(temOR)
	if len(ss) == len(lst):
		return True
	else:
		return False
t = int(input())
for _ in range(t):
	N = int(input())
	lst = list(map(int, input().split()))
	if N > 60:
		print('NO')
	else:
		z = sub_lists(lst)
		ors = distinctORs(z)
		if ors == True:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n <= 62:
		ans = set()
		for i in range(n):
			cur = 0
			c = 0
			for j in range(i, n):
				cur |= l[j]
				if cur not in ans:
					ans.add(cur)
				else:
					print('NO')
					c += 1
					break
			if c > 0:
				break
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n <= 62:
		st = set()
		for i in range(n):
			curr = 0
			for j in range(i, n):
				curr = curr | arr[j]
				st.add(curr)
		if len(st) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	if n <= 60:
		for i in range(0, n):
			ordi = 0
			for j in range(i, n):
				ordi = ordi | a[j]
				l.append(ordi | a[j])
		if len(set(l)) == len(l):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def subarrayBitwiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	k = subarrayBitwiseOR(lis)
	s = len(lis)
	if k == s * (s + 1) / 2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lis.sort(reverse=True)
	l = [0]
	for _ in range(n):
		l.append(l[_] | lis[_])
	del l[0]
	if len(list(set(l))) == len(l):
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	lim = n * (n + 1) // 2
	my_list = []
	f = 1
	for i in range(n):
		if arr[i] in my_list:
			break
		else:
			my_list.append(arr[i])
			x = arr[i]
			for j in range(i + 1, n):
				x = x | arr[j]
				if x in my_list:
					f = 0
					break
				else:
					my_list.append(x)
			if f == 0:
				break
	if len(my_list) == lim:
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	set1 = []
	for i in range(n):
		if arr[i] in set1:
			f = 1
			print('NO')
			break
		else:
			f = 0
			set1.append(arr[i])
		for j in range(i + 1, n):
			arr[i] = arr[i] | arr[j]
			if arr[i] in set1:
				f = 1
				print('NO')
				break
			else:
				set1.append(arr[i])
				f = 0
		if f == 1:
			break
	if f == 0:
		print('YES')


from functools import reduce
t = int(input())
for _ in range(t):
	n = int(input())
	k = []
	bk = False
	l = list(map(int, input().split()))
	for i in range(n):
		for j in range(i + 1, n + 1):
			z = reduce(lambda x, y: x | y, l[i:j])
			if z not in k:
				k.append(z)
			else:
				print('NO')
				bk = True
				break
		if bk:
			break
	if bk:
		continue
	print('YES')


def helper(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	distinct = helper(l)
	if distinct == n * (n + 1) / 2:
		print('YES')
	else:
		print('NO')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ar = list(map(int, input().split()))
		if n > 62:
			print('NO')
			continue
		lk = set()
		ok = True
		for sz in range(1, n + 1):
			idx = 0
			while idx + sz - 1 < n:
				curr = 0
				for j in range(idx, idx + sz):
					curr = curr | ar[j]
				if curr in lk:
					ok = False
					break
				else:
					lk.add(curr)
				idx += 1
		if ok:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


from operator import ior
import functools
for _ in range(int(input())):
	r = []
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	for i in range(n):
		for j in range(1, n - i + 1):
			k = functools.reduce(ior, l[i:i + j])
			if k in r:
				print('NO')
				flag = 1
				break
			else:
				r.append(functools.reduce(ior, l[i:i + j]))
		if flag == 1:
			break
	if flag == 0:
		print('YES')


def solve(A):
	(res, pre) = (set(), {0})
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	if solve(arr) != n * (n + 1) // 2:
		print('NO')
	else:
		print('YES')


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = []
	if n > 60:
		print('NO')
	else:
		for i in range(0, n):
			x = 0
			for j in range(i, n):
				x = x | a[j]
				p.append(x)
		if len(set(p)) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')


try:
	t = int(input())
	if 1 <= t <= 300:
		for T in range(t):
			n = int(input())
			a = list(map(int, input().split()))
			a.sort(reverse=True)
			to_add = a[0]
			f = 0
			for i in range(1, n):
				to_add = to_add | a[i]
				if to_add in a:
					f = 1
					break
				a.append(to_add)
			if f == 1:
				print('NO')
			else:
				print('YES')
except:
	pass


def frq(a):
	m = {}
	for i in a:
		if i not in m:
			m[i] = 1
		else:
			m[i] = m[i] + 1
	for (k, v) in m.items():
		if v > 1:
			return False
	return True

def ans(x):
	if frq(x) == False:
		return 'NO'
	m = []
	m.extend(x)
	for i in range(len(x)):
		for j in range(i + 1, len(x)):
			x[i] = x[i] | x[j]
			m.append(x[i])
	final = {}
	for i in m:
		if i not in final:
			final[i] = 1
		else:
			final[i] = final[i] + 1
	for (k, v) in final.items():
		if v > 1:
			return 'NO'
	return 'YES'
for i in range(int(input())):
	n = int(input())
	x = [int(n) for n in input().split()]
	if n >= 70:
		print('NO')
	else:
		print(ans(x))


def do_or(i, j, A):
	temp = 0
	for m in range(i, j + 1):
		temp |= A[m]
	return temp

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	hsh = {}
	for i in range(n):
		if A[i] in hsh.keys():
			return 'NO'
		else:
			hsh[A[i]] = 0
	or_tlb = [1] * n
	or_tlb[0] = A[0]
	for i in range(1, n):
		or_tlb[i] = or_tlb[i - 1] | A[i]
	for i in range(n):
		for j in range(i + 1, n):
			ans = do_or(i, j, A)
			if ans in hsh.keys():
				return 'NO'
			else:
				hsh[ans] = 0
	return 'YES'
tc = int(input())
for t in range(tc):
	print(solve())


from itertools import combinations
T = int(input())
for i in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	ma = max(l)
	t = 0
	if n > 62:
		t = 1
	else:

		def xor(l):
			v = l[0]
			for i in range(1, len(l)):
				e = l[i]
				v = v | e
			return v
		li = []
		fl = []
		for i in range(len(l)):
			for j in range(i, len(l)):
				li.append(l[i:j + 1])
		for e in li:
			fl.append(xor(e))
		s = set(fl)
		if len(s) == len(fl):
			pass
		else:
			t = 1
	if t == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	k = []
	l = [int(i) for i in input().split()]
	if n > 60:
		print('NO')
	else:
		ans = []
		for i in range(n):
			ord = 0
			for j in range(i, n):
				ord = ord | l[j]
				if ord not in ans:
					ans.append(ord)
		if len(ans) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')


def subarrayBitwiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = subarrayBitwiseOR(a)
	print('YES' if c == n * (n + 1) / 2 else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	f = 0
	for i in range(n):
		k = a[i]
		for j in range(i, n):
			k |= a[j]
			if k in s:
				f = 1
				print('NO')
				break
			else:
				s.add(k)
		if f:
			break
	if not f:
		print('YES')


import math
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	m = max(a)
	if n == 1:
		print('YES')
		continue
	if m == 0:
		print('NO')
		continue
	nbits = math.ceil(math.log(m + 1, 2))
	flag = True
	if n > nbits:
		flag = False
	else:
		se = set()
		for i in range(n):
			temp = a[i]
			if temp not in se:
				se.add(temp)
			else:
				flag = False
				break
			for j in range(i + 1, n):
				temp = temp | a[j]
				if temp in se:
					flag = False
					break
				else:
					se.add(temp)
			if not flag:
				break
	if flag:
		print('YES')
	else:
		print('NO')


def ors(l, r, v):
	temp = 0
	for i in range(l, r):
		temp |= v[i]
	return temp

def check(arr):
	hashmap = dict()
	if n > 70:
		print('NO')
		return
	for l in range(n):
		for r in range(l + 1, n + 1):
			ans = ors(l, r, arr)
			if hashmap.get(ans, 0):
				print('NO')
				return
			else:
				hashmap[ans] = 1
	print('YES')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	check(arr)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 62:
		st = set()
		n1 = n * (n + 1) // 2
		for i in range(n):
			m = 0
			for j in range(i, n):
				m = m | a[j]
				st.add(m)
		if len(st) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def generator(l, n):
	prev = set()
	for i in range(n):
		xor = 0
		for j in range(i, n):
			xor |= l[j]
			if xor in prev:
				flag = False
				print('NO')
				return
			prev.add(xor)
	print('YES')
for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())][:n]
	generator(l, n)


def subArrayBitWiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	d = subArrayBitWiseOR(a)
	if d == n * (n + 1) / 2:
		print('YES')
	else:
		print('NO')


def fun(ar):
	result = set()
	previous = {0}
	for i in ar:
		previous = {i | j for j in previous} | {i}
		result |= previous
	return len(result)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	k = n * (n + 1) // 2
	if fun(arr) == k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n > 60:
		print('NO')
		continue
	flag = 1
	ORset = set()
	for i in range(n):
		temp = 0
		for j in range(i, n):
			temp |= a[j]
			if temp not in ORset:
				ORset.add(temp)
			else:
				flag = 0
				break
		if flag == 0:
			break
	if flag and len(ORset) == n * (n + 1) // 2:
		print('YES')
	else:
		print('NO')


def subarrayBitwiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	seq = subarrayBitwiseOR(arr)
	if seq == n * (n + 1) // 2:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	L = list(map(int, input().split()))
	S = set({})
	if n <= 61:
		for i in range(n):
			ans = L[i]
			for j in range(i, n):
				ans |= L[j]
				S.add(ans)
		if len(S) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math
for t in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	check = set()
	if n > 60:
		print('NO')
	else:
		for i in range(n):
			check.add(values[i])
		for i in range(n):
			st = 0
			for j in range(i, n):
				st = st | values[j]
				check.add(st)
		d = n * (n + 1) // 2
		if len(check) == d:
			print('YES')
		else:
			print('NO')


from functools import *
for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	if n > 60:
		print('NO')
	else:
		b = []
		a = [L[i:i + j] for i in range(0, len(L)) for j in range(1, len(L) - i + 1)]
		for m in a:
			res = reduce(lambda x, y: x | y, m)
			b.append(res)
		b1 = set(b)
		if len(b1) == n * (n + 1) // 2:
			print('YES')
		else:
			print('NO')


def solution(a):
	st = set()
	n = len(a)
	for i in range(n):
		cur = 0
		for j in range(i, n):
			cur = cur | a[j]
			if cur in st:
				print('NO')
				return
			st.add(cur)
	print('YES')
	return
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	solution(a)


def solvor(ar):
	res = set()
	pre = {0}
	for i in ar:
		pre = {i | y for y in pre} | {i}
		res |= pre
	return len(res)
for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	x = solvor(ar)
	if x == n * (n + 1) // 2:
		print('YES')
	else:
		print('NO')


def check(arr, n):
	s = set()
	for i in range(n):
		a = arr[i]
		for j in range(i, n):
			a = a | arr[j]
			if a in s:
				return False
			else:
				s.add(a)
	return True
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if check(arr, n):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	s = []
	flag = 0
	for i in range(n):
		if a[i] in s:
			break
		else:
			s.append(a[i])
			p = a[i]
			for j in range(i + 1, n):
				p = p | a[j]
				if p in s:
					flag = 1
					break
				else:
					s.append(p)
			if flag == 1:
				break
	if len(s) == n * (n + 1) / 2:
		print('YES')
	else:
		print('NO')
	t -= 1


mod = 1000000007
read_int = lambda : int(input().strip())
read_str = lambda : input().strip()
read_str_arr = lambda : input().strip().split()
read_int_arr = lambda : [int(x) for x in input().strip().split()]

def solve():
	N = read_int()
	A = read_int_arr()
	seen = set()
	distinct = True
	for i in range(N):
		prev = 0
		for j in range(i, N):
			val = prev | A[j]
			if val in seen:
				distinct = False
				break
			else:
				seen.add(val)
			prev = val
		if not distinct:
			break
	print('YES' if distinct else 'NO')
for _ in range(int(input())):
	solve()


def orthodox(arr, n):
	unique = set()
	for i in range(n):
		Or = arr[i]
		for j in range(i, n):
			Or = Or | arr[j]
			if Or not in unique:
				unique.add(Or)
			else:
				return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(orthodox(arr, n))


def xor(A):
	res = set()
	p = {0}
	for x in A:
		p = {x | y for y in p} | {x}
		res |= p
	return len(res)
t = int(input())
for _ in range(t):
	n = int(input())
	h = [int(n) for n in input().split()]
	func = xor(h)
	res = n * (n + 1)
	res = int(res / 2)
	if func == res:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	lst = []
	if n > 60:
		print('NO')
		continue
	f = 1
	for i in range(n):
		t = 0
		for j in range(i, n):
			t = t | a[j]
			if t in lst:
				f = 0
				break
			lst.append(t)
		if f == 0:
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


test = int(input())
for t in range(test):
	FLAG = False
	n = int(input())
	a = list()
	a = list(map(int, input().strip().split()))[:n]
	second = []
	for i in range(n):
		orvalue = 0
		for j in range(i, n):
			orvalue = orvalue | a[j]
			if orvalue in second:
				FLAG = True
				break
			else:
				second.append(orvalue)
		if FLAG == True:
			break
	if FLAG == True:
		print('NO')
	else:
		print('YES')


def check(n, arr, ans):
	for i in range(n - 1):
		c = arr[i]
		for j in range(i + 1, n):
			c = c | arr[j]
			if c in ans:
				return False
			else:
				ans.append(c)
	return True
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	ans += arr
	if check(n, arr, ans):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	x = []
	if n > 62:
		print('NO')
	else:
		flag = 0
		for i in range(n):
			p = arr[i]
			for j in range(i, n):
				p = p | arr[j]
				if p in x:
					flag = 1
					break
				x.append(p)
		if flag == 1:
			print('NO')
		else:
			print('YES')


t = int(input())

def Solve(A):
	res = set()
	p = {0}
	for i in A:
		p = {i | j for j in p} | {i}
		res |= p
	return len(res)
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	distinct = Solve(A)
	if distinct == n * (n + 1) // 2:
		print('YES')
	else:
		print('NO')


def ans(A, n):
	d = {}
	for i in range(n - 1):
		d[i] = [A[i]]
		for j in range(i + 1, n):
			term = d[i][-1] | A[j]
			d[i].append(term)
	d[n - 1] = [A[-1]]
	num = set()
	for i in d.keys():
		for j in d[i]:
			num.add(j)
	if len(num) == n * (n + 1) / 2:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	if n >= 63:
		print('NO')
	else:
		print(ans(A, n))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = set()
	mx = n * ((n + 1) / 2)
	pre = {0}
	for x in arr:
		pre = {x | y for y in pre} | {x}
		res |= pre
	if len(res) == mx:
		print('YES')
	else:
		print('NO')