Given an array $a$ of positive integers with length $n$, determine if there exist three distinct indices $i$, $j$, $k$ such that $a_i + a_j + a_k$ ends in the digit $3$.


-----Input-----

The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.

The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the length of the array.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.

The sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

Output $t$ lines, each of which contains the answer to the corresponding test case. Output "YES" if there exist three distinct indices $i$, $j$, $k$ satisfying the constraints in the statement, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).


-----Examples-----

Input
6
4
20 22 19 84
4
1 11 1 2022
4
1100 1100 1100 1111
5
12 34 56 78 90
4
1 9 8 4
6
16 38 94 25 18 99
Output
YES
YES
NO
NO
YES
YES


-----Note-----

In the first test case, you can select $i=1$, $j=4$, $k=3$. Then $a_1 + a_4 + a_3 = 20 + 84 + 19 = 123$, which ends in the digit $3$.

In the second test case, you can select $i=1$, $j=2$, $k=3$. Then $a_1 + a_2 + a_3 = 1 + 11 + 1 = 13$, which ends in the digit $3$.

In the third test case, it can be proven that no such $i$, $j$, $k$ exist. Note that $i=4$, $j=4$, $k=4$ is not a valid solution, since although $a_4 + a_4 + a_4 = 1111 + 1111 + 1111 = 3333$, which ends in the digit $3$, the indices need to be distinct.

In the fourth test case, it can be proven that no such $i$, $j$, $k$ exist.

In the fifth test case, you can select $i=4$, $j=3$, $k=1$. Then $a_4 + a_3 + a_1 = 4 + 8 + 1 = 13$, which ends in the digit $3$.

In the sixth test case, you can select $i=1$, $j=2$, $k=6$. Then $a_1 + a_2 + a_6 = 16 + 38 + 99 = 153$, which ends in the digit $3$.

Difficulty: EASY

Solutions:
from collections import Counter
from itertools import combinations
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	d = Counter(map(lambda x: x[-1], input().split()))
	s = []
	for (key, value) in d.items():
		s += [int(key)] * min(value, 2)
	if d['1'] >= 3:
		s += [1]
	fl = False
	for combo in combinations(s, 3):
		if sum(combo) % 10 == 3:
			fl = True
			break
	print('YES') if fl else print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(input().split())
	arr_t = ['003', '012', '049', '058', '067', '111', '139', '148', '157', '166', '229', '238', '247', '256', '337', '346', '355', '445', '599', '689', '779', '788']
	arr = []
	for x in a:
		arr.append(x[-1])
	arr = ''.join(sorted(arr))
	hit = False
	for x in arr_t:
		a = False
		b = False
		if x[0] == x[1] and x[0] == x[2]:
			if x[0] in arr and arr.count(x[0]) >= 3:
				hit = True
				break
			else:
				continue
		elif x[0] == x[1]:
			if x[0] in arr and arr.count(x[0]) >= 2 and (x[2] in arr):
				hit = True
				break
			else:
				continue
		elif x[1] == x[2]:
			if x[1] in arr and arr.count(x[1]) >= 2 and (x[0] in arr):
				hit = True
				break
			else:
				continue
		elif x[1] in arr and x[2] in arr and (x[0] in arr):
			hit = True
			break
	if hit:
		print('YES')
	else:
		print('NO')


from itertools import combinations_with_replacement
comb = [(x, y, z) for (x, y, z) in combinations_with_replacement([i for i in range(0, 10)], 3) if (x + y + z) % 10 == 3]
m2 = []
for i in comb:
	m3 = [0] * 10
	for j in range(3):
		m3[i[j] % 10] += 1
	m2.append(m3)
t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	m1 = [0] * 10
	for i in a:
		m1[i % 10] += 1
	f = False
	for i in m2:
		fl = True
		for j in range(10):
			if m1[j] < i[j]:
				fl = False
		if fl:
			f = True
			break
	if f:
		print('YES')
	else:
		print('NO')


import sys
from collections import Counter
from itertools import product
sys.setrecursionlimit(2 * 10 ** 6)

def test():
	pass

def main():
	ns = list(range(10))
	s3 = set()
	for (a, b, c) in product(ns, ns, ns):
		if (a + b + c) % 10 == 3:
			s3.add(tuple(sorted([a, b, c])))
	s3 = [Counter(ss3) for ss3 in s3]
	N = int(input())
	for _ in range(N):
		_ = map(int, input().split())
		arr = list(map(int, input().split()))
		sa = Counter((n % 10 for n in arr))
		for ss3 in s3:
			for k in ss3.keys():
				if sa[k] < ss3[k]:
					break
			else:
				print('YES')
				break
		else:
			print('NO')

def init():
	import sys
	import os
	if 'DOCKER_HOST' in os.environ:
		test()
		sys.stdin = open('test.txt')
init()
main()


def f(arr, i, tm):
	ans = False
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			tmp = arr[j] + arr[k]
			tmp = tm % 10
			if tmp == tm:
				ans = True
				break
		if ans:
			break
	return ans
t = int(input())
for _ in range(t):
	ans = False
	n = map(int, input().split())
	arr = list(map(int, input().split()))
	ar = [0 for i in range(10)]
	for ele in arr:
		tm = ele % 10
		ar[tm] += 1
	ans = False
	for i in range(10):
		if ar[i] > 0:
			ar[i] -= 1
			for j in range(10):
				if ar[j] > 0:
					ar[j] -= 1
					tm = 23 - i - j
					tm = tm % 10
					if ar[tm] > 0:
						ans = True
						break
					ar[j] += 1
			ar[i] += 1
			if ans:
				break
	if ans:
		print('YES')
	else:
		print('NO')


def solve():
	n = input()
	arr = list(map(int, input().split()))
	temp = [0] * 10
	for i in arr:
		temp[i % 10] += 1
	for i in range(10):
		if temp[i] > 0:
			temp[i] -= 1
			for j in range(10):
				if temp[j] > 0:
					temp[j] -= 1
					for k in range(10):
						if temp[k] > 0:
							if (i + j + k) % 10 == 3:
								print('YES')
								return
					temp[j] += 1
			temp[i] += 1
	print('NO')
for T in range(int(input())):
	solve()


from collections import Counter
patterns = []
for i in range(10):
	for j in range(i, 10):
		for k in range(j, 10):
			if (i + j + k) % 10 == 3:
				patterns.append(Counter([i, j, k]))

def check(d: dict):
	for p in patterns:
		if all((d[k] >= p[k] for k in p)):
			return True
	return False

def f():
	n = int(input())
	nums = map(int, input().split())
	d = Counter((a % 10 for a in nums))
	print('YES' if check(d) else 'NO')
for _ in range(int(input())):
	f()


def thething(data, sfreq):
	freq = [0] * 10
	for i in data:
		freq[i % 10] += 1
	for a in sfreq:
		yes = True
		for b in range(10):
			if freq[b] - a[b] < 0:
				yes = False
		if yes:
			print('YES')
			return
	print('NO')
sfreq = []
for i in range(10):
	for j in range(i, 10):
		for k in range(j, 10):
			if (i + j + k) % 10 == 3:
				t1 = [0] * 10
				t1[i] += 1
				t1[j] += 1
				t1[k] += 1
				sfreq.append(t1)
num = int(input())
for n in range(num):
	_num = int(input())
	arr = [int(a) for a in input().split(' ')]
	thething(arr, sfreq)


from random import randint
l = []
for i in range(10):
	for j in range(i + 1):
		for k in range(j + 1):
			if (i + j + k) % 10 == 3:
				l.append((i, j, k))
fl = []
for (i, j, k) in l:
	f = [0] * 10
	f[i] += 1
	f[j] += 1
	f[k] += 1
	fl.append(f)
for _ in range(int(input())):
	n = int(input())
	f = [0] * 10
	for num in input().split():
		d = int(num[-1])
		f[d] += 1
	ans = 'NO'
	for pos in fl:
		if all((x >= y for (x, y) in zip(f, pos))):
			ans = 'YES'
			break
	print(ans)


import math as m
i = input()
inp = []
for a in range(0, int(i)):
	input()
	inp.append([int(x) for x in input().split()])

def logic(arr):
	counts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for n in arr:
		counts[n % 10] += 1
	arr = []
	found = False
	for i in range(10):
		freq = counts[i]
		if freq >= 3:
			if i == 1:
				return 'YES'
			else:
				arr += 2 * [i]
		else:
			arr += freq * [i]
	n = len(arr)
	for i in range(n - 2):
		a = arr[i]
		for j in range(i + 1, n - 1):
			b = arr[j]
			for k in range(j + 1, n):
				if (a + b + arr[k]) % 10 == 3:
					return 'YES'
	return 'NO'
for arr in inp:
	print(logic(arr))


filters = [0, 0, 3, 0, 1, 2, 0, 4, 9, 0, 5, 8, 0, 6, 7, 1, 1, 1, 1, 3, 9, 1, 4, 8, 1, 5, 7, 1, 6, 6, 2, 2, 9, 2, 3, 8, 2, 4, 7, 2, 5, 6, 3, 3, 7, 3, 4, 6, 3, 5, 5, 4, 4, 5, 5, 9, 9, 6, 8, 9, 7, 7, 9, 7, 8, 8]
rules = []
one_to_ten = [_ for _ in range(10)]
for i in range(int(len(filters) / 3)):
	_filter = filters[i * 3:i * 3 + 3]
	_rule = {i: _filter.count(i) for i in one_to_ten}
	rules.append({key: val for (key, val) in _rule.items() if val != 0})

def rule_applies(_counter, _rule):
	for key in _rule.keys():
		if _counter[key] < _rule[key]:
			return False
	return True
for i in range(int(input())):
	n = int(input())
	counter = [0] * 10
	for num in input().split():
		counter[int(num) % 10] += 1
	for rule in rules:
		if rule_applies(counter, rule):
			print('YES')
			break
	else:
		print('NO')


from collections import defaultdict

def main():
	t = int(input())
	memo = [[0, 0, 3], [0, 1, 2], [0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 1, 1], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8]]
	while t:
		t -= 1
		n = int(input())
		arr = list(map(int, input().split()))
		last = defaultdict(int)
		for e in arr:
			last[e % 10] += 1
		unique = last.keys()
		n = len(unique)
		check(last, memo)

def check(last, memo):
	for e in memo:
		(i, j, k) = e
		if i == 1 and j == 1 and (k == 1) and (last[1] >= 3):
			print('YES')
			return
		if i == j and j != k and (last[i] >= 2) and (last[k] > 0):
			print('YES')
			return
		if j == k and k != i and (last[j] >= 2) and (last[i] > 0):
			print('YES')
			return
		if i != j and j != k and (last[i] > 0) and (last[j] > 0) and (last[k] > 0):
			print('YES')
			return
	print('NO')
main()


for t in range(int(input())):
	n = int(input())
	data = {i: 0 for i in range(10)}
	for num in input().split():
		a = int(num) % 10
		data[a] += 1
	in_use = {i: 0 for i in range(10)}
	for i in range(10):
		if data[i] == 0:
			continue
		in_use[i] += 1
		check = False
		for j in range(10):
			if data[j] - in_use[j] == 0:
				continue
			in_use[j] += 1
			sm = i + j
			need = 10 * (sm // 10) + 3 - sm
			if need < 0:
				need += 10
			if data[need] - in_use[need] != 0:
				print('YES')
				check = True
				in_use[j] -= 1
				break
			in_use[j] -= 1
		in_use[i] -= 1
		if check:
			break
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	old_nums = [int(x) % 10 for x in input().split()]
	count = [0] * 10
	nums = []
	for i in old_nums:
		if count[i] < 3:
			count[i] += 1
			nums.append(i)
	pos = {}
	for i in range(len(nums)):
		if nums[i] not in pos:
			pos[nums[i]] = i

	def solve():
		for i in range(2, len(nums)):
			for j in range(1, i):
				nums_k = (3 - nums[i] - nums[j]) % 10
				if pos.get(nums_k, j) < j:
					print('YES')
					return
		print('NO')
	solve()


from collections import Counter

def solve():
	n = int(input())
	arr = [int(i) % 10 for i in input().split()]
	c = Counter(arr)
	for i in range(10):
		for j in range(i, 10):
			for k in range(j, 10):
				if (i + j + k) % 10 == 3:
					if i == j == k:
						if c[i] > 2:
							return 'YES'
					elif i == j:
						if c[i] > 1 and c[k] > 0:
							return 'YES'
					elif j == k:
						if c[j] > 1 and c[i] > 0:
							return 'YES'
					elif c[i] > 0 and c[j] > 0 and (c[k] > 0):
						return 'YES'
	return 'NO'

def main():
	for _ in range(int(input())):
		print(solve())
	return
main()


l = []
for i in range(10):
	for j in range(10):
		for k in range(10):
			if (i + j + k) % 10 == 3:
				dic = {}
				dic[i] = 1 + dic.get(i, 0)
				dic[j] = 1 + dic.get(j, 0)
				dic[k] = 1 + dic.get(k, 0)
				l += [dic]
for i in range(int(input())):
	n = int(input())
	d = {}
	for j in range(10):
		d[j] = 0
	arr = [int(I) % 10 for I in input().split()]
	for i in arr:
		d[i] += 1
	for t in l:
		flag2 = True
		for i in t:
			if t[i] > d[i]:
				flag2 = False
				break
		if flag2:
			break
	if flag2:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
l = [i for i in range(10)]
dp = []
for i in range(10):
	for j in range(i, 10):
		for k in range(j, 10):
			if (i + j + k) % 10 == 3:
				if i == j and j == k:
					dp.append([(i, 3)])
				elif i == j:
					dp.append([(i, 2), (k, 1)])
				elif j == k:
					dp.append([(i, 1), (k, 2)])
				else:
					dp.append([(i, 1), (j, 1), (k, 1)])
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	narr = list(map(lambda x: x % 10, arr))
	d = defaultdict(int)
	for x in narr:
		d[x] += 1
	flag = True
	for per in dp:
		ft = True
		for req in per:
			if d[req[0]] < req[1]:
				ft = False
				break
		if ft:
			print('YES')
			flag = False
			break
	if flag:
		print('NO')


for i in range(int(input())):
	n = int(input())
	arr = [int(x) % 10 for x in input().split()]
	data = [0 for x in range(10)]
	for x in arr:
		data[x] += 1
	flag = False
	l = 10
	for a in range(l):
		if data[a] < 1:
			continue
		for b in range(a, l):
			if data[b] < 1:
				continue
			if a == b and data[a] < 2:
				continue
			for c in range(b, l):
				if data[c] < 1:
					continue
				if a == b and b == c and (data[a] < 3):
					continue
				if b == c and data[b] < 2:
					continue
				if (a + b + c) % 10 == 3:
					print('YES')
					flag = True
					break
			if flag:
				break
		if flag:
			break
	if not flag:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	num_list = [0] * 10
	for i in a:
		num_list[i % 10] += 1
	for i in range(10):
		for j in range(10):
			num_list[i] -= 1
			num_list[j] -= 1
			if num_list[i] >= 0 and num_list[j] >= 0 and (num_list[(3 - (i + j)) % 10] >= 1):
				print('YES')
				break
			num_list[i] += 1
			num_list[j] += 1
		else:
			continue
		break
	else:
		print('NO')


sets = [{0, 1, 2}, {0, 9, 4}, {0, 8, 5}, {0, 6, 7}, {1, 3, 9}, {8, 1, 4}, {1, 5, 7}, {8, 2, 3}, {2, 4, 7}, {2, 5, 6}, {3, 4, 6}, {8, 9, 6}]
for i in range(int(input())):
	n = int(input())
	arr = list(map(lambda x: int(x[-1]), input().split()))
	cnt = [arr.count(i) for i in range(10)]
	arr_set = set(arr)
	if arr.count(1) >= 3:
		print('YES')
		continue
	if cnt[0] >= 2 and cnt[3] >= 1 or (cnt[6] >= 2 and cnt[1] >= 1) or (cnt[2] >= 2 and cnt[9] >= 1) or (cnt[3] >= 2 and cnt[7] >= 1) or (cnt[5] >= 2 and cnt[3] >= 1) or (cnt[4] >= 2 and cnt[5] >= 1) or (cnt[9] >= 2 and cnt[5] >= 1) or (cnt[7] >= 2 and cnt[9] >= 1) or (cnt[8] >= 2 and cnt[7] >= 1):
		print('YES')
		continue
	for subset in sets:
		if subset.issubset(arr_set):
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(a) % 10 for a in input().split()]
	count = {}
	for a in arr:
		count[a] = count.get(a, 0) + 1
	flag = True
	for (k1, v1) in count.items():
		if 3 * k1 % 10 == 3 and v1 >= 3:
			print('YES')
			flag = False
			break
		for (k2, v2) in count.items():
			if k1 != k2:
				if (2 * k1 + k2) % 10 == 3 and v1 >= 2 or ((k1 + 2 * k2) % 10 == 3 and v2 >= 2):
					print('YES')
					flag = False
					break
				for k3 in count:
					if k3 not in [k1, k2] and (k1 + k2 + k3) % 10 == 3:
						print('YES')
						flag = False
						break
				if not flag:
					break
		if not flag:
			break
	if flag:
		print('NO')


import sys
import collections
import bisect
import math
from functools import lru_cache
sys.setrecursionlimit(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	arr = sys.stdin.readline().split()
	dic = {}
	for num in arr:
		x = int(num[-1])
		if x not in dic:
			dic[x] = 0
		dic[x] += 1
	flag = False
	res = [[0, 0, 3], [0, 1, 2], [1, 1, 1], [0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8]]
	ans = False
	for l in res:
		flag = True
		for num in set(l):
			if num not in dic or dic[num] < l.count(num):
				flag = False
				break
		if flag:
			ans = True
			break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = [{0: 2, 3: 1}, {0: 1, 1: 1, 2: 1}, {0: 1, 4: 1, 9: 1}, {0: 1, 5: 1, 8: 1}, {0: 1, 6: 1, 7: 1}, {1: 3}, {1: 1, 3: 1, 9: 1}, {1: 1, 4: 1, 8: 1}, {1: 1, 5: 1, 7: 1}, {1: 1, 6: 2}, {2: 2, 9: 1}, {2: 1, 3: 1, 8: 1}, {2: 1, 4: 1, 7: 1}, {2: 1, 5: 1, 6: 1}, {3: 2, 7: 1}, {3: 1, 4: 1, 6: 1}, {3: 1, 5: 2}, {4: 2, 5: 1}, {5: 1, 9: 2}, {6: 1, 8: 1, 9: 1}, {7: 2, 9: 1}, {7: 1, 8: 2}]
	a = [int(i) % 10 for i in input().strip().split()]
	d = {}
	for i in range(n):
		d[a[i]] = d.get(a[i], 0) + 1
	check = False
	for ds in l:
		check = True
		for k in ds:
			if d.get(k, 0) < ds[k]:
				check = False
				break
		if check:
			break
	if check:
		print('YES')
	else:
		print('NO')


prs = [{0: 2, 3: 1}, {0: 1, 1: 1, 2: 1}, {0: 1, 4: 1, 9: 1}, {0: 1, 5: 1, 8: 1}, {0: 1, 6: 1, 7: 1}, {1: 3}, {1: 1, 3: 1, 9: 1}, {1: 1, 4: 1, 8: 1}, {1: 1, 5: 1, 7: 1}, {1: 1, 6: 2}, {2: 2, 9: 1}, {2: 1, 3: 1, 8: 1}, {2: 1, 4: 1, 7: 1}, {2: 1, 5: 1, 6: 1}, {3: 2, 7: 1}, {3: 1, 4: 1, 6: 1}, {3: 1, 5: 2}, {4: 2, 5: 1}, {5: 1, 9: 2}, {6: 1, 8: 1, 9: 1}, {7: 2, 9: 1}, {7: 1, 8: 2}]
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sl = {}
	for x in a:
		os = x % 10
		if os not in sl:
			sl[os] = 1
		else:
			sl[os] += 1
	w = False
	for pr in prs:
		q = True
		for r in pr.keys():
			if r not in sl or pr[r] > sl[r]:
				q = False
				break
		if q:
			w = True
			break
	if w:
		print('YES')
	else:
		print('NO')


from collections import defaultdict

def makecondititions():
	conditions = []
	for a in range(10):
		for b in range(10):
			for c in range(10):
				if (a + b + c) % 10 == 3:
					condition = defaultdict(int)
					for val in (a, b, c):
						condition[val] += 1
					conditions.append(condition)
	return conditions

def check(mapping, conditions):
	for condition in conditions:
		if all([mapping[key] >= condition[key] for key in condition]):
			return 'YES'
	return 'NO'
conditions = makecondititions()
for _ in range(int(input())):
	n = int(input())
	array = map(int, input().split(' '))
	mapping = defaultdict(int)
	for item in array:
		mapping[item % 10] += 1
	print(check(mapping, conditions))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		d[a[i] % 10] += 1
	fl = False
	for x in range(10):
		for y in range(10):
			z = (10 - (x + y) % 10) % 10
			z = (z + 3) % 10
			d[x] -= 1
			d[z] -= 1
			d[y] -= 1
			if d[x] >= 0 and d[z] >= 0 and (d[y] >= 0):
				fl = True
				break
			else:
				d[x] += 1
				d[y] += 1
				d[z] += 1
	if fl:
		print('YES')
	else:
		print('NO')


from itertools import combinations

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(i) % 10 for i in input().split()]
		a_set = set(a)
		a_pair = []
		for element in a_set:
			for i in range(min(3, a.count(element))):
				a_pair.append(element)
		found = False
		for combination in combinations(a_pair, 3):
			if sum(combination) % 10 == 3:
				found = True
				break
		if found:
			print('YES')
		else:
			print('NO')
main()


import sys
from os import path
from typing import List

def get_int():
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
	input = int(sys.stdin.readline())
	return input

def compute():
	table: List[dict] = []
	for a in range(10):
		for b in range(10):
			for c in range(10):
				s = a + b + c
				if s % 10 == 3:
					t = {}
					t[a] = 1
					if b not in t:
						t[b] = 1
					else:
						t[b] += 1
					if c not in t:
						t[c] = 1
					else:
						t[c] += 1
					table.append(t)
	return table
LOOKUP = compute()

def is_sat(buckets, solution: dict):
	for (b, n) in solution.items():
		if len(buckets[b]) < n:
			return False
	return True

def is_solved(buckets):
	for solution in LOOKUP:
		if is_sat(buckets, solution):
			return True
	return False

def solve(a):
	buckets = {}
	for i in range(10):
		buckets[i] = []
	for n in a:
		b = n % 10
		buckets[b].append(n)
	if is_solved(buckets):
		print('YES')
		return
	print('NO')
num_lines = get_int() if path.exists('input.txt') else int(sys.stdin.readline())
while num_lines > 0:
	sys.stdin.readline()
	a = [int(t) for t in sys.stdin.readline().replace('\n', '').split(' ')]
	solve(a)
	num_lines -= 1


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = [aa % 10 for aa in a]
	numDict = defaultdict(int)
	for aa in a:
		numDict[aa] += 1
	flag = False
	for i in range(10):
		for j in range(i, 10):
			for k in range(j, 10):
				if (i + j + k) % 10 == 3:
					if i != j and j != k and (k != i):
						if numDict[i] >= 1 and numDict[j] >= 1 and (numDict[k] >= 1):
							flag = True
					elif i == j and j != k:
						if numDict[i] >= 2 and numDict[k] >= 1:
							flag = True
					elif i != j and j == k:
						if numDict[j] >= 2 and numDict[i] >= 1:
							flag = True
					elif i == j and j == k:
						if numDict[i] >= 3:
							flag = True
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	q = [0 for i in range(10)]
	for i in a:
		q[i % 10] += 1
	s = list(q)
	c = False
	for i in range(len(q)):
		if q[i] == 0:
			continue
		q = list(s)
		q[i] -= 1
		t = list(q)
		for j in range(len(q)):
			if q[j] == 0:
				continue
			q = list(t)
			q[j] -= 1
			for k in range(len(q)):
				if q[k] == 0:
					continue
				if (i + j + k) % 10 == 3:
					print('YES')
					c = True
					break
			if c:
				break
		if c:
			break
	if not c:
		print('NO')


import sys
try:
	sys.stdin = open('input.txt')
except FileNotFoundError:
	pass
q = []
for i in range(10):
	for j in range(i, 10):
		for k in range(j, 10):
			if (i + j + k) % 10 == 3:
				qq = [0 for i in range(10)]
				qq[i] += 1
				qq[j] += 1
				qq[k] += 1
				q.append(qq)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) % 10 for j in input().split()]
	b = [0 for i in range(10)]
	for j in a:
		b[j] += 1
	ww = 0
	for j in q:
		for k in range(10):
			if b[k] < j[k]:
				ww += 1
				break
	print('YES' if ww < len(q) else 'NO')


sample = [[0, 0, 3], [0, 1, 2], [0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 1, 1], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8]]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [el % 10 for el in a]
	a.sort()
	dic = {}
	for el in a:
		dic[el] = 0
	for el in a:
		dic[el] += 1
	flag = False
	for temp in sample:
		if temp[0] in dic and temp[1] in dic and (temp[2] in dic):
			dic[temp[0]] -= 1
			dic[temp[1]] -= 1
			dic[temp[2]] -= 1
			if dic[temp[0]] >= 0 and dic[temp[1]] >= 0 and (dic[temp[2]] >= 0):
				flag = True
			dic[temp[0]] += 1
			dic[temp[1]] += 1
			dic[temp[2]] += 1
	if flag:
		print('YES')
	else:
		print('NO')


from collections import Counter
from itertools import combinations
for _ in range(int(input())):
	n = int(input())
	counter = Counter((int(x) % 10 for x in input().split()))
	for x in counter:
		counter[x] = min(counter[x], 3)
	if any((sum(x) % 10 == 3 for x in combinations(counter.elements(), 3))):
		print('YES')
	else:
		print('NO')


data = []
for i in range(10):
	for j in range(10):
		for k in range(10):
			if (i + j + k) % 10 == 3:
				data.append(str(i) + str(j) + str(k))
for i in range(int(input())):
	yes = False
	n = int(input())
	arr = list(map(int, input().split()))
	for j in range(len(arr)):
		arr[j] = str(arr[j] % 10)
	s = ''.join(arr)
	for j in data:
		if all((k in s for k in j)) and j.count(j[0]) <= s.count(j[0]) and (j.count(j[1]) <= s.count(j[1])) and (j.count(j[2]) <= s.count(j[2])):
			print('YES')
			yes = True
			break
	if not yes:
		print('NO')


from collections import Counter

def sum_generator(total, num):
	if num == 1:
		yield (total,)
	else:
		for digit in range((total - 1) // num + 1, min(total, 9) + 1):
			for way in sum_generator(total - digit, num - 1):
				yield (way + (digit,))

def plans():
	for t in range(3, 33, 10):
		for way in sum_generator(t, 3):
			yield Counter(way)
num_of_cases = int(input())
for case in range(num_of_cases):
	input()
	numbers = map(lambda s: int(s[-1]), input().split())
	num_count = Counter(numbers)
	for aplan in plans():
		if all((aplan[dig] <= num_count[dig] for dig in aplan)):
			print('YES')
			break
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n,) = map(int, input().split())
	a = list(map(int, input().split()))
	s = defaultdict(int)
	for i in a:
		s[i % 10] += 1
	f = False
	c = [0] * 10
	for i in range(10):
		if c[i] == s[i]:
			continue
		c[i] += 1
		for j in range(10):
			if c[j] == s[j]:
				continue
			c[j] += 1
			for k in range(10):
				if c[k] == s[k]:
					continue
				c[k] += 1
				if (i + j + k) % 10 == 3:
					print('YES')
					f = True
					break
				c[k] -= 1
			if f:
				break
			c[j] -= 1
		if f:
			break
		c[i] -= 1
	if not f:
		print('NO')


import collections
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % 10
	v = [[0, 0, 3], [0, 1, 2], [0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 1, 1], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8]]
	d = collections.Counter(a)
	find = False
	for i in v:
		c = collections.Counter(i)
		ok = True
		for j in c.keys():
			if d[j] < c[j]:
				ok = False
		find = find or ok
	if find:
		print('YES')
	else:
		print('NO')


ans = []
for i in range(10):
	for j in range(10):
		for k in range(10):
			if (i + j + k) % 10 == 3:
				ans.append([i, j, k])
n = int(input())
for i in range(n):
	z = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for k in range(z):
		a[k] = a[k] % 10
		if a[k] in d:
			d[a[k]] += 1
		else:
			d[a[k]] = 1
	flag = 0
	for j in range(len(ans)):
		if ans[j][0] in d and ans[j][1] in d and (ans[j][2] in d):
			d[ans[j][0]] -= 1
			d[ans[j][1]] -= 1
			d[ans[j][2]] -= 1
			if d[ans[j][0]] > -1 and d[ans[j][1]] > -1 and (d[ans[j][2]] > -1):
				flag = 1
				break
			else:
				d[ans[j][0]] += 1
				d[ans[j][1]] += 1
				d[ans[j][2]] += 1
	if flag == 1:
		print('YES')
	else:
		print('NO')


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_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	n = int(input())
	arr = get_list()
	hm = [0 for _ in range(10)]
	for i in range(n):
		hm[arr[i] % 10] += 1
	flag = 0
	for i in range(10):
		if hm[i] > 0:
			hm[i] -= 1
			for j in range(10):
				if hm[j] > 0:
					hm[j] -= 1
					for k in range(10):
						if hm[k] > 0:
							hm[k] -= 1
							if (i + j + k) % 10 == 3:
								flag = 1
								break
							hm[k] += 1
					hm[j] += 1
					if flag == 1:
						break
			if flag == 1:
				break
			hm[i] += 1
	if flag == 1:
		print('YES')
		continue
	print('NO')


def findTriple(r):
	for a in range(0, 10):
		for b in range(0, 10):
			c = (23 - a - b) % 10
			if r[a] != 0 and r[b] != 0 and (r[c] != 0):
				if a == b and b == c and (r[a] < 3):
					continue
				if (a == b or b == c) and r[b] < 2:
					continue
				if a == c and r[a] < 2:
					continue
				print('YES')
				return
	print('NO')
	return
n = int(input())
for i in range(0, n):
	amount = int(input())
	rem = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for j in input().split():
		rem[int(j) % 10] = rem[int(j) % 10] + 1
	findTriple(rem)


import sys
I = sys.stdin.readline
O = sys.stdout.write

def three_sum(arr, n):
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			for k in range(j + 1, n):
				if (arr[i] + arr[j] + arr[k]) % 10 == 3:
					return 'YES'
	return 'NO'
t = int(I())
for _ in range(t):
	n = int(I())
	arr = list(map(int, I().split()))
	d = dict()
	for each in arr:
		if each % 10 not in d:
			d[each % 10] = 1
		elif d[each % 10] < 3:
			d[each % 10] += 1
	set_arr = []
	for (k, v) in d.items():
		set_arr.extend([k] * v)
	O(str(three_sum(set_arr, len(set_arr))) + '\n')


def solve():
	n = int(input())
	lis = list(map(int, input().split()))
	cnt = [0] * 10
	li = list()
	for i in lis:
		above = i % 10
		cnt[above] += 1
		if cnt[above] <= 3:
			li.append(i)
	m = len(li)
	for i in range(m):
		for j in range(i + 1, m):
			for k in range(j + 1, m):
				cur_val = li[i] + li[j] + li[k]
				if cur_val % 10 == 3:
					print('YES')
					return
	print('NO')
for _ in range(int(input())):
	solve()


def find_3sum():
	n = int(input())
	a = [int(x) % 10 for x in input().split()]
	freqDict = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}
	modList = []
	mlLength = 0
	for j in range(n):
		if freqDict[a[j]] < 3:
			freqDict[a[j]] += 1
			modList.append(a[j])
			mlLength += 1
	for j in range(mlLength - 2):
		for k in range(j + 1, mlLength - 1):
			for l in range(k + 1, mlLength):
				if (modList[j] + modList[k] + modList[l]) % 10 == 3:
					return 'YES'
	return 'NO'
t = int(input())
for i in range(t):
	print(find_3sum())


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [0] * 10
	for x in arr:
		dp[x % 10] += 1
	flag = False
	for i in range(10):
		for j in range(10):
			dp[i] -= 1
			dp[j] -= 1
			if dp[i] >= 0 and dp[j] >= 0 and (dp[(3 - (i + j)) % 10] >= 1):
				flag = True
			dp[i] += 1
			dp[j] += 1
	print('YES' if flag else 'NO')


p = lambda : map(int, input().split())

def solve():
	n = int(input())
	a = [k % 10 for k in p()]
	cnt = [0] * 10
	for k in a:
		cnt[k] += 1
	b = []
	for i in range(10):
		for j in range(min(cnt[i], 3)):
			b += (i,)
	for i in range(len(b)):
		for j in range(i):
			for k in range(j):
				if (b[i] + b[j] + b[k]) % 10 == 3:
					print('YES')
					return
	print('NO')
	return
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	a = [int(i) % 10 for i in input().split()]
	d = dict()
	for i in a:
		d[i] = d.get(i, 0) + 1
	found = False
	for i in range(10):
		if d.get(i, 0) < 1:
			continue
		d[i] -= 1
		for j in range(10):
			if d.get(j, 0) < 1:
				continue
			d[j] -= 1
			for k in range(10):
				if d.get(k, 0) < 1:
					continue
				d[k] -= 1
				if (i + j + k) % 10 == 3:
					print('YES')
					found = True
					break
				d[k] += 1
			if found:
				break
			d[j] += 1
		if found:
			break
		d[i] += 1
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	k = [0] * 10
	a = list(map(int, input().split()))
	for i in a:
		k[i % 10] += 1
	ans = 0
	for i in range(10):
		sm = 0
		if k[i]:
			k[i] -= 1
			sm += i
			for j in range(10):
				sm = i
				if k[j]:
					k[j] -= 1
					sm += j
					for l in range(10):
						sm = i + j
						if k[l]:
							k[l] -= 1
							sm += l
							if sm % 10 == 3:
								ans = 1
								break
							k[l] += 1
						if ans:
							break
					k[j] += 1
				if ans:
					break
			k[i] += 1
		if ans:
			break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	x = int(input())
	a = input().split()
	k = 0
	for i in range(8):
		k += i
	b = []
	for i in a:
		b.append(int(i[-1]))
	d = {}
	for i in b:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	e = 0
	if 1 in d.keys():
		if d[1] >= 3:
			e = 1
			print('YES')
	if e == 0 and 3 in d.keys() and (0 in d.keys()):
		if d[3] >= 1 and d[0] >= 2:
			e = 1
			print('YES')
	op = 0
	for i in range(8):
		op += 1
	if e == 0:
		lor = []
		for i in d.keys():
			if d[i] == 1:
				lor.append(i)
			if d[i] >= 2:
				lor.append(i)
				lor.append(i)
				d[i] = 0
		badam = len(lor)
		for i in range(badam):
			if e == 1:
				break
			for j in range(i + 1, badam):
				if e == 1:
					break
				for k in range(j + 1, badam):
					f = lor[i] + lor[j] + lor[k]
					if str(f)[-1] == '3':
						print('YES')
						e = 1
						break
	if e == 0:
		print('NO')


res = []

def Sum(nums, n):
	c = [0] * 10
	arr = []
	for n in nums:
		n %= 10
		if c[n] + 1 <= 3:
			c[n] += 1
			arr.append(n)
	for i in range(len(arr)):
		for j in range(i + 1, len(arr)):
			for k in range(j + 1, len(arr)):
				if (arr[i] + arr[j] + arr[k]) % 10 == 3:
					res.append('YES')
					return
	res.append('NO')
	return
t = int(input())
while t:
	m = int(input())
	A = list(map(int, input().split()))
	Sum(A, m)
	t -= 1
for x in res:
	print(x)


t = int(input())

def threeSum(a, n):
	newArr = []
	count = [0] * 10
	for item in a:
		count[item] += 1
	for i in range(10):
		for j in range(min(count[i], 3)):
			newArr.append(i)
	m = len(newArr)
	for i in range(m):
		for j in range(i + 1, m):
			for k in range(j + 1, m):
				if (newArr[i] + newArr[j] + newArr[k]) % 10 == 3:
					return 'YES'
	return 'NO'
while t != 0:
	a = []
	n = int(input())
	temp = input()
	a = temp.split(' ')
	a = list(map(lambda x: int(x) % 10, a))
	print(threeSum(a, n))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	temp = input().split()
	lasts = [int(i[-1]) for i in temp]
	d = {}
	for i in lasts:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	res = 0
	if 1 in d.keys():
		if d[1] >= 3:
			res = 1
			print('YES')
	if res == 0 and 3 in d.keys() and (0 in d.keys()):
		if d[3] >= 1 and d[0] >= 2:
			res = 1
			print('YES')
	if res == 0:
		newnums = []
		for i in d.keys():
			if d[i] == 1:
				newnums.append(i)
			if d[i] >= 2:
				newnums.append(i)
				newnums.append(i)
				d[i] = 0
		for i in range(len(newnums)):
			if res == 1:
				break
			for j in range(i + 1, len(newnums)):
				if res == 1:
					break
				for k in range(j + 1, len(newnums)):
					su = newnums[i] + newnums[j] + newnums[k]
					if str(su)[-1] == '3':
						print('YES')
						res = 1
						break
	if res == 0:
		print('NO')


from collections import Counter

def solve(n, a):
	a = [ele % 10 for ele in a]
	c = Counter(a)
	new_a = []
	for ele in c:
		if c[ele] >= 3:
			new_a.extend([ele, ele, ele])
		elif c[ele] == 2:
			new_a.extend([ele, ele])
		else:
			new_a.append(ele)
	for i in range(len(new_a)):
		for j in range(i + 1, len(new_a)):
			for k in range(j + 1, len(new_a)):
				if (new_a[i] + new_a[j] + new_a[k]) % 10 == 3:
					return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(component) for component in input().split(' ')]
	print(solve(n, a))


t = int(input())
while t:
	n = int(input())
	a = [int(x) % 10 for x in input().split()]
	d = dict.fromkeys(a, 0)
	li = []
	for i in a:
		d[i] += 1
		if i == 1:
			if d[i] <= 3:
				li.append(i)
		elif d[i] < 3:
			li.append(i)
	n = len(li)
	ok = 0
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			for k in range(j + 1, n):
				if (li[i] + li[j] + li[k]) % 10 == 3:
					print('YES')
					ok = 1
					break
			if ok:
				break
		if ok:
			break
	else:
		print('NO')
	t -= 1


def func(x):
	return int(x) % 10
for _ in range(int(input())):
	n = int(input())
	a = [0 for i in range(10)]
	l = list(map(func, input().split()))
	for i in l:
		a[i] += 1
	t = []
	t += a
	flag = 0
	for i in range(10):
		if flag == 1:
			break
		t = []
		t += a
		ans = 0
		if t[i] == 0:
			continue
		for j in range(10):
			if flag == 1:
				break
			t = []
			t += a
			t[i] -= 1
			if t[j] == 0:
				continue
			ans = i + j
			t[j] -= 1
			for k in range(10):
				if t[k] == 0:
					continue
				if (ans + k - 3) % 10 == 0:
					flag = 1
					break
	if flag:
		print('YES')
	else:
		print('NO')


def solve(b):
	for i in range(len(b)):
		for j in range(i):
			for k in range(j):
				if (b[i] + b[j] + b[k]) % 10 == 3:
					return True
	return False
T = int(input())
for test in range(T):
	N = int(input())
	array = list(map(int, input().split()))
	for i in range(N):
		array[i] = array[i] % 10
	b = []
	for i in range(10):
		for j in range(min(array.count(i), 3)):
			b.append(i)
	if solve(b):
		print('YES')
	else:
		print('NO')


from collections import Counter
import sys
ipt = sys.stdin.readline
for _ in range(int(input())):
	n = ipt()
	f = list(map(lambda x: int(x) % 10, ipt().split()))
	c = Counter(f)
	r = []
	for (k, v) in c.items():
		r += min(v, 3) * [k]
	answ = 'NO'
	for i in range(len(r) - 2):
		if answ == 'YES':
			break
		for j in range(i + 1, len(r) - 1):
			if answ == 'YES':
				break
			for k in range(j + 1, len(r)):
				if (r[i] + r[j] + r[k]) % 10 == 3:
					answ = 'YES'
					break
	print(answ)


from collections import Counter, defaultdict
from email.policy import default
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	modCounts = defaultdict(int)
	for i in arr:
		modCounts[i % 10] += 1
	v = [[0, 0, 3], [0, 1, 2], [0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 1, 1], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8]]
	bflag = 0
	for c in v:
		ll = Counter(c)
		flag = 0
		for (j, m) in ll.items():
			if modCounts[j] < m:
				flag = 1
				break
		if flag == 0:
			bflag = 1
			print('YES')
			break
	if bflag == 0:
		print('NO')


def find_3sum():
	n = int(input())
	a = [int(x) % 10 for x in input().split()]
	arr = []
	for x in a:
		if arr.count(x) < 3:
			arr.append(x)
	l = len(arr)
	cnt = 0
	for i in range(l - 2):
		for j in range(i + 1, l - 1):
			for k in range(j + 1, l):
				if (arr[i] + arr[j] + arr[k]) % 10 == 3:
					return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	print(find_3sum())


t = int(input())

def solve():
	n = int(input())
	nums = input()
	nums = [int(x) for x in nums.split()]
	dict = {}
	for i in range(0, 10):
		dict[i] = 0
	for i in range(len(nums)):
		dict[nums[i] % 10] += 1
	lista = []
	for i in range(0, 10):
		for j in range(min(3, dict[i])):
			lista.append(i)
	for i in range(len(lista)):
		for j in range(i + 1, len(lista)):
			for k in range(j + 1, len(lista)):
				if (lista[i] + lista[j] + lista[k]) % 10 == 3:
					print('YES')
					return
	print('NO')
while t:
	t = t - 1
	solve()


def solve():
	n = int(input())
	s = list(map(int, input().split()))
	a = []
	for x in s:
		z = x % 10
		if a.count(z) < 3:
			a.append(z)
	for i in range(len(a)):
		for j in range(i):
			for k in range(j):
				if (a[i] + a[j] + a[k]) % 10 == 3:
					return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	for i in range(n):
		A[i] = A[i] % 10
	A.sort()
	B = [A[0]]
	c = 1
	for i in range(1, n):
		if A[i] == B[-1] and c == 3:
			continue
		if A[i] == B[-1]:
			B.append(A[i])
			c += 1
		else:
			B.append(A[i])
			c = 1
	m = len(B)
	for i in range(m - 2):
		for j in range(i + 1, m - 1):
			for k in range(j + 1, m):
				if (B[i] + B[j] + B[k]) % 10 == 3:
					print('YES')
					return
	print('NO')
t = int(input())
while t != 0:
	solve()
	t -= 1


from collections import Counter
t = int(input())
for k in range(t):
	n = int(input())
	arr = [int(i) % 10 for i in input().split()]
	ct = Counter(arr)
	out = []
	kk = list(ct.keys())
	kk.sort()
	for key in kk:
		maxRep = min(ct[key], 3)
		for j in range(maxRep):
			out.append(key)
	l = len(out)
	flag = False
	for a in range(l):
		for b in range(a + 1, l):
			for c in range(b + 1, l):
				if (out[a] + out[b] + out[c]) % 10 == 3:
					flag = True
					break
			if flag:
				break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


import collections
t = int(input())
for _ in range(t):
	input()
	counts = collections.Counter([v[-1] for v in input().split()])
	els = []
	for (d, c) in counts.items():
		for _ in range(min(c, 3)):
			els.append(int(d))
	res = False
	for i in range(len(els)):
		for j in range(i + 1, len(els)):
			for k in range(j + 1, len(els)):
				if (els[i] + els[j] + els[k]) % 10 == 3:
					res = True
					break
			if res:
				break
		if res:
			break
	if res:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	input()
	s = (*(x % 10 for x in [*map(int, input().split())]),)
	l = []
	cnt = 0
	for i in range(10):
		l.append(s.count(i))
	for i in range(10):
		l[i] -= 1
		for j in range(i, 10):
			l[j] -= 1
			for k in range(j, 10):
				l[k] -= 1
				if l[i] >= 0 and l[j] >= 0 and (l[k] >= 0):
					if (i + j + k) % 10 == 3:
						cnt = 1
						break
				l[k] += 1
			if cnt:
				break
			l[j] += 1
		if cnt:
			break
		l[i] += 1
	print('YNEOS'[cnt != 1::2])


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	d = dict()
	for i in range(10):
		d[i] = 0
	for x in arr:
		d[x % 10] += 1
	for i in range(10):
		for j in range(10):
			for k in range(10):
				if (i + j + k) % 10 == 3:
					if d[i] > 0:
						d[i] -= 1
						if d[j] > 0:
							d[j] -= 1
							if d[k] > 0:
								d[k] -= 1
								print('YES')
								return
							d[j] += 1
						d[i] += 1
	print('NO')
t = int(input())
for i in range(t):
	solve()


import sys
input = sys.stdin.readline

def solve():
	for i in range(10):
		for j in range(10):
			for k in range(10):
				if (i + j + k) % 10 == 3:
					if i == j == k:
						if check[i] >= 3:
							return True
					elif i == j:
						if check[i] >= 2 and check[k] >= 1:
							return True
					elif j == k:
						if check[j] >= 2 and check[i] >= 1:
							return True
					elif i == k:
						if check[i] >= 2 and check[j] >= 1:
							return True
					elif check[i] >= 1 and check[j] >= 1 and (check[k] >= 1):
						return True
	return False
for _ in range(int(input())):
	n = int(input())
	nums = [*map(lambda x: int(x) % 10, input().split())]
	check = [0] * 10
	for num in nums:
		check[num] += 1
	print('YES' if solve() else 'NO')


class T:

	def __init__(self):
		self.l = [int(el) for el in input().split()]
		self.a = [[0, 4, 9], [0, 5, 8], [0, 6, 7], [1, 3, 9], [1, 4, 8], [1, 5, 7], [1, 6, 6], [2, 2, 9], [2, 3, 8], [2, 4, 7], [2, 5, 6], [3, 3, 7], [3, 4, 6], [3, 5, 5], [4, 4, 5], [5, 9, 9], [6, 8, 9], [7, 7, 9], [7, 8, 8], [0, 1, 2], [1, 1, 1], [0, 0, 3]]
		for i in range(len(self.l)):
			self.l[i] = self.l[i] % 10

	def mycheck(self):
		for i in range(len(self.a)):
			if self.l.count(self.a[i][0]) >= self.a[i].count(self.a[i][0]) and self.l.count(self.a[i][1]) >= self.a[i].count(self.a[i][1]) and (self.l.count(self.a[i][2]) >= self.a[i].count(self.a[i][2])):
				return 'YES'
		return 'NO'

	def __repr__(self):
		print(self.l)
t = int(input())
for i in range(t):
	n = int(input())
	a2 = T()
	print(a2.mycheck())


for t in range(int(input())):
	n = int(input())
	d2c = {}
	for i in input().split():
		d2c[int(i) % 10] = d2c.get(int(i) % 10, 0) + 1
	i = 0
	flag = 0
	while flag == 0 and i < 10:
		j = i
		while flag == 0 and j < 10:
			k = j
			while flag == 0 and k < 10:
				if (i + j + k) % 10 == 3:
					t2c = {}
					for t in (i, j, k):
						t2c[t] = t2c.get(t, 0) + 1
					if t2c[i] <= d2c.get(i, 0) and t2c[j] <= d2c.get(j, 0) and (t2c[k] <= d2c.get(k, 0)):
						flag = 1
				k += 1
			j += 1
		i += 1
	print('YES' if flag else 'NO')


from collections import defaultdict
for _ in [0] * int(input()):
	n = int(input())
	a = [*map(int, input().split())]
	d = defaultdict(lambda : 0)
	ans = 'NO'
	for i in a:
		d[i % 10] += 1
	for i in range(10):
		for j in range(10):
			k = (3 - i - j) % 10
			if i == j == k and d[i] >= 3:
				ans = 'YES'
			if i == j != k and d[i] >= 2 and (d[k] >= 1):
				ans = 'YES'
			if i == k != j and d[i] >= 2 and (d[j] >= 1):
				ans = 'YES'
			if j == k != i and d[j] >= 2 and (d[i] >= 1):
				ans = 'YES'
			if i != j and j != k and (k != i) and (d[i] >= 1) and (d[j] >= 1) and (d[k] >= 1):
				ans = 'YES'
	print(ans)


from collections import Counter

def solve():
	input()
	r = Counter()
	a = []
	for x in input().split():
		x = int(x) % 10
		r[x] += 1
		if r[x] <= 3:
			a.append(x)
	for i in range(len(a)):
		for j in range(i):
			for k in range(j):
				if (a[i] + a[j] + a[k]) % 10 == 3:
					return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


from collections import defaultdict, deque, Counter
from functools import lru_cache
from heapq import heappush, heappop
from bisect import bisect_right, bisect_left

def inpNum():
	return int(input())

def inpStr():
	return input()

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

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

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

def find3Sum(unitDigitMap):
	for i in range(10):
		for j in range(10):
			for k in range(10):
				if (i + j + k) % 10 == 3:
					if i == j == k:
						if unitDigitMap[i] >= 3:
							return True
					elif i == j:
						if unitDigitMap[i] >= 2 and unitDigitMap[k] > 0:
							return True
					elif i == k:
						if unitDigitMap[i] >= 2 and unitDigitMap[j] > 0:
							return True
					elif j == k:
						if unitDigitMap[j] >= 2 and unitDigitMap[i] > 0:
							return True
					elif unitDigitMap[i] > 0 and unitDigitMap[j] > 0 and (unitDigitMap[k] > 0):
						return True
	return False
tc = inpNum()
for _ in range(tc):
	n = inpNum()
	nums = inpNumList()
	unitDigitMap = defaultdict(int)
	for i in nums:
		unitDigitMap[i % 10] += 1
	if find3Sum(unitDigitMap):
		print('YES')
	else:
		print('NO')


from collections import Counter

def solver():
	n = int(input())
	li2 = []
	c = Counter()
	for a in input().split():
		a = int(a) % 10
		c[a] += 1
		if c[a] <= 3:
			li2.append(a)
	for j in range(len(li2)):
		for k in range(j):
			for l in range(k):
				if (li2[j] + li2[k] + li2[l]) % 10 == 3:
					return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solver())


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

def solve():
	n = int(input())
	a = read()
	h = [0] * 10
	for e in a:
		h[e % 10] += 1
	for i in range(10):
		for j in range(10):
			for k in range(10):
				if (i + j + k) % 10 != 3:
					continue
				h[i] -= 1
				h[j] -= 1
				h[k] -= 1
				if h[i] >= 0 and h[j] >= 0 and (h[k] >= 0):
					print('YES')
					return
				h[i] += 1
				h[j] += 1
				h[k] += 1
	print('NO')
t = int(input())
for i in range(t):
	solve()


a = []
for i in range(0, 10):
	for j in range(0, 10):
		for k in range(0, 10):
			num = i + j + k
			if num % 10 == 3:
				a.append([i, j, k])
t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		num = li[i] % 10
		if num in d:
			d[num] += 1
		else:
			d[num] = 1
	y = 0
	for i in range(len(a)):
		tp = dict()
		num1 = a[i][0]
		num2 = a[i][1]
		num3 = a[i][2]
		if num1 in tp:
			tp[num1] += 1
		else:
			tp[num1] = 1
		if num2 in tp:
			tp[num2] += 1
		else:
			tp[num2] = 1
		if num3 in tp:
			tp[num3] += 1
		else:
			tp[num3] = 1
		c = 0
		for j in tp:
			if j in d:
				if d[j] >= tp[j]:
					c += tp[j]
		if c == 3:
			y = 1
			break
	if y == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	cnt = [0] * 10
	for i in input().split():
		cnt[int(i[-1])] += 1
	arr = []
	for i in range(10):
		arr = arr + [i] * min(cnt[i], 3)
	m = len(arr)
	flag = False
	for i in range(m):
		for j in range(i + 1, m):
			for k in range(j + 1, m):
				if (arr[i] + arr[j] + arr[k]) % 10 == 3:
					flag = True
					break
			if flag:
				break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	d = Counter(map(lambda x: x[-1], input().split()))
	l = []
	f = False
	for (k, v) in d.items():
		if v > 3:
			l += [int(k)] * 3
		else:
			l += [int(k)] * v
	f = False
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			for k in range(j + 1, len(l)):
				if (l[i] + l[j] + l[k]) % 10 == 3:
					f = True
					break
			if f:
				break
		if f:
			break
	print('YES' if f else 'NO')


ret = []
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = dict()
	for i in l:
		k = i % 10
		if k not in d:
			d[k] = 0
		d[k] += 1
	for z in d:
		x = min(3, d[z])
		d[z] = x
	li = []
	for z in d:
		for y in range(d[z]):
			li.append(z)
	l1 = len(li)
	zzz = 0
	for i in range(l1):
		if zzz == 1:
			break
		for j in range(i + 1, l1):
			if zzz == 1:
				break
			for k in range(j + 1, l1):
				if (li[i] + li[j] + li[k]) % 10 == 3:
					ret.append('YES')
					zzz = 1
					break
	if zzz == 0:
		ret.append('NO')
for y in ret:
	print(y)


from collections import Counter
i = int(input())
for x in range(i):
	n = int(input())
	l = list(map(int, input().split()))
	arr = [x % 10 for x in l]
	c = Counter(arr)
	v = []
	flag = False
	for x in c:
		v += [x] * min(3, c[x])
	for i in range(len(v) - 2):
		for j in range(i + 1, len(v) - 1):
			for k in range(j + 1, len(v)):
				if (v[i] + v[j] + v[k]) % 10 == 3:
					flag = True
					break
				if flag:
					break
			if flag:
				break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


ans = []
for d1 in range(10):
	for d2 in range(10):
		for d3 in range(10):
			if (d1 + d2 + d3) % 10 == 3:
				s = [d1, d2, d3]
				s.sort()
				ans.append(s)
ans.sort()
ans2 = [ans[0]]
for i in range(1, len(ans)):
	if ans[i] == ans[i - 1]:
		continue
	else:
		ans2.append(ans[i])
t = int(input())
for ooo in range(t):
	N = int(input())
	a = [int(i) % 10 for i in input().split()]
	a.sort()
	key = False
	for i in ans2:
		count = 0
		for digit in i:
			if i.count(digit) <= a.count(digit):
				count += 1
		if count == 3:
			key = True
			print('YES')
			break
	if key == False:
		print('NO')


def determiner(counts):
	for i in range(10):
		for j in range(10):
			for k in range(10):
				if (i + j + k) % 10 == 3:
					if i == j == k and counts[i] > 2:
						return True
					elif i == j != k and counts[i] > 1 and (counts[k] > 0):
						return True
					elif i != j == k and counts[i] > 0 and (counts[k] > 1):
						return True
					elif i != j != k != i and counts[i] > 0 and (counts[j] > 0) and (counts[k] > 0):
						return True
	return False
tests = int(input())
for _ in range(tests):
	length = int(input())
	nums = list(map(int, input().split()))
	counts = [0] * 10
	for i in nums:
		counts[i % 10] += 1
	if determiner(counts):
		print('YES')
	else:
		print('NO')