You are given an array of $n$ integers $a_1, a_2, \dots, a_n$

You can apply the following operation an arbitrary number of times:

select an index $i$ ($1 \le i \le n$) and replace the value of the element $a_i$ with the value $a_i + (a_i mod 10)$, where $a_i mod 10$ is the remainder of the integer dividing $a_i$ by $10$.

For a single index (value $i$), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of $a_i$ is taken into account each time. For example, if $a_i=47$ then after the first operation we get $a_i=47+7=54$, and after the second operation we get $a_i=54+4=58$.

Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.

For example, you have an array $[6, 11]$.

Let's apply this operation to the first element of the array. Let's replace $a_1 = 6$ with $a_1 + (a_1 mod 10) = 6 + (6 mod 10) = 6 + 6 = 12$. We get the array $[12, 11]$.

Then apply this operation to the second element of the array. Let's replace $a_2 = 11$ with $a_2 + (a_2 mod 10) = 11 + (11 mod 10) = 11 + 1 = 12$. We get the array $[12, 12]$.

Thus, by applying $2$ operations, you can make all elements of an array equal.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. What follows is a description of each test case.

The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the size of the array.

The second line of each test case contains $n$ integers $a_i$ ($0 \le a_i \le 10^9$) — array elements.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case print:

YES if it is possible to make all array elements equal;

NO otherwise.

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


-----Examples-----

Input
10
2
6 11
3
2 18 22
5
5 10 5 10 5
4
1 2 4 8
2
4 5
3
93 96 102
2
40 6
2
50 30
2
22 44
2
1 5
Output
Yes
No
Yes
Yes
No
Yes
No
No
Yes
No


-----Note-----

The first test case is clarified above.

In the second test case, it is impossible to make all array elements equal.

In the third test case, you need to apply this operation once to all elements equal to $5$.

In the fourth test case, you need to apply this operation to all elements until they become equal to $8$.

In the fifth test case, it is impossible to make all array elements equal.

In the sixth test case, you need to apply this operation to all elements until they become equal to $102$.

Difficulty: MEDIUM
Tags: Number theory

Mathematics

Complete search
Skill types: Complete search

Starter code:

Solutions:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
t = int(input())
for _ in range(t):
	n = int(input())
	I = list(map(int, input().split()))
	Ans = [-1] * 3
	check = True
	A1 = [1, 2, 4, 8]
	A2 = [3, 6, 7, 9]
	for num in I:
		if num % 10 == 0:
			if Ans[2] == -1:
				Ans[2] = num
			elif Ans[2] != num:
				check = False
				break
		elif num % 10 == 5:
			if Ans[2] == -1:
				Ans[2] = num + 5
			elif Ans[2] != num + 5:
				check = False
				break
		elif num % 10 in A1:
			if num % 20 < 10:
				Ans[0] = 1
			else:
				Ans[1] = 1
		elif num % 20 < 10:
			Ans[1] = 1
		else:
			Ans[0] = 1
	cnt = 0
	for i in Ans:
		if i == -1:
			cnt += 1
	if cnt != 2:
		check = False
	if check:
		print('Yes')
	else:
		print('No')


from operator import xor
from typing import List

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		print('Yes' if problem(n, arr) else 'No')

def problem(n: int, arr: List[int]) -> bool:
	classes = [classify(x) for x in arr]
	return all((x == classes[0] for x in classes))

def classify(n: int) -> int:
	(left, digit) = divmod(n, 10)
	if digit == 0 or digit == 5:
		if digit == 0:
			return n
		else:
			return n + 5
	if xor(left % 2, digit in {1, 2, 4, 8}):
		return -100
	else:
		return -200
import sys
input = sys.stdin.readline
sys.exit(main())


def category(n):
	if n % 5 == 0:
		return (n + 5) // 10 * 10
	elif n % 10 in [1, 2, 4, 8]:
		k = n % 100 // 10
		return k % 2 + 1
	else:
		k = n % 100 // 10
		return (k + 1) % 2 + 1
testcase = int(input())
for _ in range(testcase):
	n = int(input())
	arr = [int(num) for num in input().split()]
	arr2 = [category(num) for num in arr]
	if len(set(arr2)) == 1:
		print('Yes')
	else:
		print('No')


standard_input = '10\n2\n6 11\n3\n2 18 22\n5\n5 10 5 10 5\n4\n1 2 4 8\n2\n4 5\n3\n93 96 102\n2\n40 6\n2\n50 30\n2\n22 44\n2\n1 5\n'

def goTo8(n):
	if n % 5 == 0:
		return -1
	while n % 10 != 8:
		n = (n + n % 10) % 20
	return n
for _ in range(int(input())):
	n = int(input())
	a = sorted(set(map(int, input().split())), reverse=True)
	if a[0] % 5 == 0:
		number = a[0] if a[0] % 10 == 0 else a[0] + 5
		for v in a:
			if not (v == number or v == number - 5):
				print('No')
				break
		else:
			print('Yes')
	else:
		a = sorted(set((i % 20 for i in a)))
		number = goTo8(a[0])
		for v in a:
			if goTo8(v) != number:
				print('No')
				break
		else:
			print('Yes')


import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	a = list(map(int, inp().split()))
	c = [0] * 10
	for i in a:
		c[i % 10] += 1
	if c[0] != 0 or c[5] != 0:
		if sum(c) - c[0] - c[5] != 0:
			print('No')
			return
		for i in range(n):
			if a[i] % 10 == 5:
				a[i] += 5
		if a.count(a[0]) == n:
			print('Yes')
		else:
			print('No')
		return
	z = [0, 0, 4 + 8 + 6, 6, 8 + 6]
	v = None
	for i in range(n):
		if a[i] % 2 == 1:
			a[i] += a[i] % 10
		x = (a[i] + z[a[i] % 10 // 2]) % 20
		if v is None:
			v = x
		elif v != x:
			print('No')
			return
	print('Yes')

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


def ss(l):
	n = len(l)
	d = {1: 15, 2: 14, 3: 3, 4: 12, 6: 0, 7: 19, 8: 8, 9: 17}
	f10 = 0
	f5 = 0
	f10mx = 0
	for i in range(n):
		if l[i] % 10 == 0:
			f10 = 1
			f10mx = max(f10mx, l[i])
		elif l[i] % 10 == 5:
			f5 = 1
		else:
			l[i] += d[l[i] % 10]
	if f10 == 1:
		mx = f10mx
		for i in l:
			if mx - i == 0 or mx - i == 5:
				continue
			else:
				return 'No'
		return 'Yes'
	if f5 == 1:
		if len(set(l)) == 1:
			return 'Yes'
		return 'No'
	mx = max(l)
	for i in l:
		if (mx - i) % 20 != 0:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(ss(l))


import sys
input = sys.stdin.readline
U = lambda : map(int, input().split())
T = int(input())
for h in range(T):
	n = int(input())
	a = [*U()]
	A = [i % 10 for i in a]
	k = list(set(a))
	if 0 in A:
		if len(k) == 1:
			y = 1
		elif len(k) == 2:
			(p, q) = sorted(k)
			if p % 10 == 5 and p + 5 == q:
				y = 1
			else:
				y = 0
		else:
			y = 0
	elif 5 in A:
		if len(k) == 1:
			y = 1
		else:
			y = 0
	else:
		b = [w // 10 % 2 for w in a]
		c = [(w in [1, 2, 4, 8]) + 0 for w in A]
		e = [b[i] ^ c[i] for i in range(n)]
		if len(list(set(e))) == 2:
			y = 0
		else:
			y = 1
	print(['No', 'Yes'][y])


from sys import stdin, stdout

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

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

def logic(n, arr):
	categ = [0] * n
	p = 0
	for x in arr:
		if x % 10 in [1, 2, 4, 8]:
			if x // 10 % 2 == 0:
				cat = 0
			else:
				cat = 1
		elif x % 10 in [3, 6, 7, 9]:
			if x // 10 % 2 == 0:
				cat = 1
			else:
				cat = 0
		else:
			cat = -1
		categ[p] = cat
		p += 1
	if -1 in categ:
		if 0 in categ or 1 in categ:
			return 'No'
		a = [arr[i] for i in range(n) if categ[i] == -1]
		b = a[0]
		b += 5 * (b % 10 == 5)
		for x in a:
			x += 5 * (x % 10 == 5)
			if x != b:
				return 'No'
		return 'Yes'
	if not (1 in categ and 0 in categ):
		return 'Yes'
	return 'No'
for w in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = [int(x) for x in stdin.readline().split()]
	print(logic(n, arr))


def solve(n, a):
	diff10s = set()
	isodd = False
	iseven = False
	for v in a:
		if v % 10 in {5, 7, 9, 6}:
			v += v % 10
		if v % 10 == 3:
			v += 3 + 6
		if v % 10 == 0:
			diff10s.add(v)
			continue
		if v // 10 % 2 == 0:
			iseven = True
		else:
			isodd = True
	return len(diff10s) + isodd + iseven < 2

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = [int(v) for v in input().split()]
		if solve(n, a):
			print('Yes')
		else:
			print('No')
main()


t = int(input())

def next(x):
	return x + x % 10

def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	flag = False
	for i in range(n):
		if lst[i] % 5 == 0:
			flag = True
			lst[i] = next(lst[i])
	if flag:
		mini = min(lst)
		maxi = max(lst)
		if mini == maxi:
			print('Yes')
		else:
			print('No')
	else:
		flag1 = False
		flag12 = False
		for i in range(len(lst)):
			x = lst[i]
			while x % 10 != 2:
				x = next(x)
			if x % 20 == 2:
				flag1 = True
			else:
				flag12 = True
		if flag1 and flag12:
			print('No')
		else:
			print('Yes')
for i in range(t):
	solve()


def solve():
	tc = list()
	n = int(input())
	for i in range(n):
		x = int(input())
		tc.append(list(map(int, str(input()).split())))
	for test in tc:
		if mod10Possible(test):
			print('Yes')
		else:
			print('No')

def mod10Possible(test):
	for i in range(len(test)):
		val = test[i]
		while val % 10 != 2:
			if not val % 10:
				break
			val += val % 10
		test[i] = val
	if test[0] % 10:
		b = test[0] % 20
		for val in test:
			if val % 20 != b:
				return False
		return True
	else:
		return len(set(test)) == 1
solve()


def val(x):
	if x == 0:
		return 0
	if x == 1:
		return 1
	if x == 2:
		return 0
	if x == 3:
		return 9
	if x == 4:
		return -2
	if x == 5:
		return 5
	if x == 6:
		return 6
	if x == 7:
		return 5
	if x == 8:
		return -6
	if x == 9:
		return 3
t = int(input())
for i in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	flag = 0
	for j in range(n):
		x = inp[j] % 10
		inp[j] += val(x)
		if x == 5 or x == 0:
			if inp[j] != inp[0]:
				flag = 1
				break
		elif (inp[j] - inp[0]) % 20 != 0:
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')


def operation(n):
	n += n % 10
	return n

def operationmod2(n):
	if n % 10 == 0 or n % 10 == 5:
		return n
	while n % 10 != 2:
		n += n % 10
	return n

def arrayequal(arr):
	for i in range(len(arr) - 1):
		if arr[i] != arr[i + 1]:
			return False
	return True

def arraytype2(arr):
	typemod = arr[0] % 20
	for i in range(len(arr)):
		if arr[i] % 20 != typemod:
			return False
	return True

def modulo10(m, arr):
	group = 0
	if arr[0] % 10 == 0 or arr[0] % 10 == 5:
		group = 1
	else:
		group = 2
	if group == 1:
		for i in range(m):
			arr[i] = operation(arr[i])
		if arrayequal(arr):
			return 'Yes'
		return 'No'
	if group == 2:
		for i in range(m):
			arr[i] = operationmod2(arr[i])
		if arraytype2(arr):
			return 'Yes'
		return 'No'

def main():
	n = int(input())
	for i in range(n):
		m = int(input())
		arr = [int(i) for i in input().split()]
		print(modulo10(m, arr))
main()


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	q = set()
	for i in a:
		while i % 10 != 0 and i % 10 != 2:
			i += i % 10
		if i % 10 != 0:
			i %= 20
		q.add(i)
	return 'Yes' if len(q) == 1 else 'No'
t = int(input())
q = []
while t:
	q.append(solve())
	t -= 1
print('\n'.join(q))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = set()
	for el in a:
		if el % 5 == 0:
			res.add(el + el % 10)
			continue
		while el % 10 != 6:
			el += el % 10
		res.add(el % 20)
	print('Yes' if len(res) == 1 else 'No')


def op(n):
	return n + n % 10

def main():
	n = int(input())
	nums = list(map(int, input().split()))
	del5 = 0
	for i in range(n):
		if nums[i] % 5 == 0:
			del5 += 1
	if del5 == n:
		nums = list(map(op, nums))
		res = all(map(lambda x: x == nums[0], nums))
		print('Yes' if res else 'No')
		return
	if del5 == 0:
		for i in range(n):
			while nums[i] % 10 != 2:
				nums[i] = op(nums[i])
		res = all(map(lambda x: x % 20 == nums[0] % 20, nums))
		print('Yes' if res else 'No')
		return
	print('No')
for _ in range(int(input())):
	main()


TTT = int(input())
L1 = [3, 6]
L0 = [0, 2, 4, 8]
while TTT:
	n = int(input())
	flag = [0, 0, 0]
	s = list(input().split(' '))
	l = list(map(len, s))
	s5 = []
	for i in range(n):
		wei = s[i][-1]
		if wei == '5':
			flag[2] = 1
			s5.append(int(s[i]) + 5)
		elif wei == '0':
			flag[2] = 1
			s5.append(int(s[i]))
		elif wei == '3' or wei == '6' or wei == '9' or (wei == '7'):
			ind = 1
			if l[i] > 1:
				ind += int(s[i][:-1]) % 2
			flag[ind % 2] = 1
		else:
			ind = 0
			if l[i] > 1:
				ind += int(s[i][:-1]) % 2
			flag[ind % 2] = 1
	if sum(flag) > 1:
		print('No')
	elif flag[2] == 1:
		s5.sort()
		if s5[0] == s5[-1]:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')
	TTT -= 1


for _ in range(int(input())):
	input()
	(c1, c3, c5) = [0] * 3
	z = []
	for i in map(int, input().split()):
		i += i % 10
		(x, y) = (i // 10 % 10, i % 10)
		if i % 5 == 0:
			c5 = 1
			z.append(i)
		elif x % 2 and y == 6 or (x % 2 == 0 and (not y == 6)):
			c1 = 1
		else:
			c3 = 1
	if any((z[0] != i for i in z)):
		c1 = c3 = c5 = 1
	print('YNeos'[not c1 ^ c3 ^ c5 or c1 & c3 & c5::2])


n = int(input())
for _ in range(n):
	m = int(input())
	A = list(map(int, input().split()))
	(two, zero) = (False, False)
	for i in range(m):
		while A[i] % 10 not in [0, 2]:
			A[i] += A[i] % 10
		if A[i] % 10 == 2:
			two = True
		else:
			zero = True
	if two and zero:
		print('No')
	else:
		if two:
			Aset = set([A[i] % 20 for i in range(m)])
		else:
			Aset = set(A)
		if len(Aset) == 1:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	rem = set()
	for x in a:
		while x % 10 and x % 10 != 2:
			x += x % 10
		if x % 10:
			x %= 20
		rem.add(x)
	print('Yes' if len(rem) == 1 else 'No')


a = int(input())
for _ in range(a):
	b = int(input())
	c = [int(x) for x in input().split()]
	fexist = -1
	zexist = -1
	oexist = False
	answer = True
	collect = -1
	for i in range(b):
		if c[i] % 10 == 5:
			if fexist == -1 or fexist == c[i]:
				fexist = c[i]
			else:
				answer = False
				break
		elif c[i] % 10 == 0:
			if zexist == -1 or zexist == c[i]:
				zexist = c[i]
			else:
				answer = False
				break
		else:
			oexist = True
			ten = int(c[i] / 10) % 2
			c[i] = c[i] % 10
			if c[i] == 8 or c[i] == 2 or c[i] == 4 or (c[i] == 1):
				ten = 1 - ten
			if collect == -1:
				collect = ten
			if ten != collect:
				answer = False
				break
	if answer == False:
		print('No')
	elif zexist != -1 or fexist != -1:
		if oexist == True:
			answer = False
		elif zexist != -1 and fexist != -1:
			if fexist + 5 != zexist:
				answer = False
		if answer == False:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	e = len(list(set(a)))
	f5 = []
	b = []
	c = []
	s = 0
	for i in range(n):
		f = a[i]
		if f % 5 == 0:
			b.append(3)
			f += f % 10
			f5.append(f)
			s = 1
		else:
			while f % 10 != 6:
				f += f % 10
			if (f % 100 - 6) // 10 % 2 == 0:
				b.append(2)
			else:
				b.append(1)
	f5 = len(list(set(f5)))
	b = len(list(set(b)))
	if b == 1:
		if s == 1:
			if f5 == 1:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
	else:
		print('No')


def make2(a):
	while a % 10 != 2:
		a += a % 10
	return a
q = int(input())
for _ in range(q):
	k = int(input())
	arr = list(map(int, input().split()))
	if all((s % 5 == 0 for s in arr)):
		ss = set(arr)
		if len(ss) == 2:
			maxx = max(ss)
			minn = min(ss)
			if minn + minn % 10 == maxx:
				print('Yes')
			else:
				print('No')
		elif len(ss) == 1:
			print('Yes')
		else:
			print('No')
	elif any((s % 5 == 0 for s in arr)):
		print('No')
	else:
		arr1 = []
		for el in arr:
			arr1.append(make2(el))
		ok = True
		for i in range(1, k):
			dif = arr1[i] - arr1[i - 1]
			ok = ok and dif % 20 == 0
		if ok:
			print('Yes')
		else:
			print('No')


from re import L
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	rem = set()
	for x in l:
		while x % 10 and x % 10 != 2:
			x += x % 10
		if x % 10:
			x %= 20
		rem.add(x)
	if len(rem) == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	ans = True
	if l[0] % 10 in [0, 5]:
		cy5 = True
	else:
		cy5 = False
	for i in range(len(l)):
		if (l[i] % 10 in [0, 5]) != cy5:
			ans = False
			break
		if cy5:
			while l[i] % 10 != 0:
				l[i] += l[i] % 10
		else:
			while l[i] % 10 != 2:
				l[i] += l[i] % 10
	if ans == False:
		print('No')
		continue
	for i in range(0, len(l) - 1):
		if cy5:
			if l[i + 1] != l[i]:
				ans = False
				break
		elif abs(l[i + 1] - l[i]) % 20 != 0:
			ans = False
			break
	if ans:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = set()
	for i in range(len(a)):
		if a[i] % 10 == 5:
			a[i] += a[i] % 10
			d.add(a[i])
		if a[i] % 10 == 0:
			d.add(a[i])
		else:
			while a[i] % 10 != 2:
				a[i] += a[i] % 10
			d.add(a[i] % 20)
	if len(d) == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for q in range(t):
	n = int(input())
	l = [int(j) for j in input().split()]

	def equal(m):
		if m % 10 == 0:
			for i in range(0, n):
				if m - l[i] != 0:
					return 0
			return 1
		for i in range(0, n):
			x = (m - l[i]) % 20
			if x == 0 and i == n - 1:
				return 1
			elif x != 0:
				return 0
	for i in range(0, n):
		while l[i] % 10 != 2 and l[i] % 10 != 0:
			l[i] = l[i] + l[i] % 10
	m = max(l)
	k = equal(m)
	if k == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	for i in range(len(l)):
		if l[i] % 10 == 5:
			l[i] += l[i] % 10
			s.add(l[i])
		if l[i] % 10 == 0:
			s.add(l[i])
		else:
			while l[i] % 10 != 2:
				l[i] += l[i] % 10
			s.add(l[i] % 20)
	if len(s) == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


possible = dict()
for num in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
	possible[num] = {num}
	cur = (num + num) % 10
	while cur not in possible[num]:
		possible[num].add(cur)
		cur = (cur + cur) % 10
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		a[i] = a[i] + a[i] % 10
	ends = set(map(lambda x: x % 10, a))
	if 0 in ends and ends != {0}:
		print('No')
	elif 0 in ends:
		print('Yes' * (len(set(a)) == 1) + 'No' * (len(set(a)) != 1))
	else:
		for i in range(len(a)):
			while a[i] % 10 != 2:
				a[i] = a[i] + a[i] % 10
		fail = False
		for i in range(1, len(a)):
			if (a[i] - a[0]) % 20 != 0:
				print('No')
				fail = True
				break
		if not fail:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	h = {}
	flag = 0
	for i in range(n):
		if a[i] % 2 == 1:
			a[i] += a[i] % 10
		if a[i] % 10 == 0:
			h[a[i]] = h.get(a[i], 0) + 1
		else:
			while a[i] % 10 != 2:
				a[i] += a[i] % 10
			h[a[i] % 20] = h.get(a[i] % 20, 0) + 1
		if len(h) > 1:
			print('No')
			flag = 1
			break
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	temp = False
	for i in range(n):
		if l[i] % 5 == 0 and l[i] % 10 != 0:
			l[i] += 5
		if l[i] % 5 == 0 or l[i] % 10 == 0:
			temp = True
	if temp:
		flag = True
		for i in range(n - 1):
			if l[i] != l[i + 1]:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
	else:
		for i in range(n):
			if l[i] % 2:
				l[i] += l[i] % 10
		mn = min(l)
		flag = True
		for i in range(n):
			no = l[i]
			no += (mn - no) // 20 * 20
			while no < mn:
				no += no % 10
			if no > mn:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')


from math import *
a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	for y in range(b):
		if c[y] % 10 % 2 == 1:
			c[y] = c[y] + c[y] % 10
		if c[y] % 10 == 6:
			c[y] = c[y] + 6
		if c[y] % 10 == 5:
			c[y] = c[y] + 5
	ze = 0
	p = 0
	for y in range(b):
		if c[y] % 10 == 0:
			ze += 1
		else:
			p += 1
	if p > 0 and ze > 0:
		print('No')
	elif p == 0 and ze > 0:
		if c.count(c[0]) == b:
			print('Yes')
		else:
			print('No')
	else:
		c.sort()
		f = 0
		o = c[-1] // 10
		for y in range(b - 1):
			if c[-1] == c[y]:
				continue
			elif o % 2 != c[y] // 10 % 2:
				f = -1
				break
		if f == -1:
			print('No')
		else:
			print('Yes')