Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. 
An array is Rainbow if it has the following structure:
- First a1 elements equal 1. 
- Next a2 elements equal 2. 
- Next a3 elements equal 3. 
- Next a4 elements equal 4. 
- Next a5 elements equal 5. 
- Next a6 elements equal 6. 
- Next a7 elements equal 7. 
- Next a6 elements equal 6. 
- Next a5 elements equal 5. 
- Next a4 elements equal 4. 
- Next a3 elements equal 3. 
- Next a2 elements equal 2. 
- Next a1 elements equal 1. 
- ai can be any non-zero positive integer.
- There are no other elements in array. 

Help Chef in finding out if the given array is a Rainbow Array or not. 

-----Input-----
- The first line of the input contains an integer T denoting the number of test cases.
- The first line of each test case contains an integer N, denoting the number of elements in the given array. 
- The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of array. 

-----Output-----
- For each test case, output a line containing "yes" or "no" (without quotes) corresponding to the case if the array is rainbow array or not. 

-----Constraints-----
- 1 ≤ T ≤ 100
- 7 ≤ N ≤ 100
- 1 ≤ Ai ≤ 10

-----Subtasks-----
- Subtask 1 (100 points) : Original constraints

-----Example-----
Input
3
19
1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1
14
1 2 3 4 5 6 7 6 5 4 3 2 1 1
13
1 2 3 4 5 6 8 6 5 4 3 2 1

Output
yes
no
no

-----Explanation-----
The first example satisfies all the conditions. 
The second example has 1 element of value 1 at the beginning and 2 elements of value 1 at the end. 
The third one has no elements with value 7 after elements with value 6.

Difficulty: MEDIUM
Tags: Amortized analysis

Implementation
Skill types: Amortized analysis

Starter code:

Solutions:
t = int(input())
x = [1, 2, 3, 4, 5, 6, 7]
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	l = s[::-1]
	r = set(s)
	if s == l and list(r) == x:
		print('yes')
	else:
		print('no')


import math
T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	lst = [1, 2, 3, 4, 5, 6, 7]
	if len(A) < 13:
		print('no')
	else:
		check_lst = all((item in lst for item in A))
		check_A = all((item in A for item in lst))
		if check_lst and check_A:
			if A == A[::-1]:
				half_lst = A[0:math.ceil(len(A) / 2)]
				half_lst_sorted = A[0:math.ceil(len(A) / 2)]
				half_lst_sorted.sort()
				if half_lst_sorted == half_lst:
					print('yes')
				else:
					print('no')
			else:
				print('no')
		else:
			print('no')


def rbow(a, n):
	for i in range(1, 8):
		if i not in a:
			return 'no'
	l = n // 2 if n % 2 == 0 else n // 2 + 1
	for i in range(1, l):
		if a[i] < a[i - 1]:
			return 'no'
	for i in range(l):
		if a[i] != a[-(i + 1)]:
			return 'no'
	return 'yes'
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(rbow(a, n))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 1
	rainbow = True
	for i in range(n // 2 + 1):
		if a[i] == a[n - i - 1] and (a[i] == x or a[i] == x + 1):
			x = a[i]
		else:
			rainbow = False
			break
	if rainbow and a[n // 2] == 7:
		print('yes')
	else:
		print('no')


tests = int(input())
for i in range(tests):
	length = int(input())
	arr = list(map(int, input().split()))
	repetitions = [0] * 7
	exists = [0] * 7
	ans = 'yes'
	seven_found = False
	for j in range(length):
		if j != 0 and (seven_found and arr[j] > arr[j - 1] or (not seven_found and arr[j] < arr[j - 1])):
			ans = 'no'
			break
		if arr[j] > 7:
			ans = 'no'
			break
		else:
			exists[arr[j] - 1] = 1
		if arr[j] == 7:
			seven_found = True
		elif not seven_found:
			repetitions[arr[j] - 1] += 1
		else:
			repetitions[arr[j] - 1] -= 1
	if min(repetitions) != 0 or max(repetitions) != 0 or sum(exists) != 7:
		ans = 'no'
	print(ans)


t = int(input())
for i in range(t):
	l = int(input())
	li = list(map(int, input().split()))[:l]
	a = []
	b = [1, 2, 3, 4, 5, 6, 7]
	c = li[::-1]
	for i in li:
		if i not in a:
			a.append(i)
	a.sort()
	if a == b and li == c:
		print('yes')
	else:
		print('no')


T = int(input())
for __ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	flag = 1
	if l[i] != 1:
		flag = 0
	else:
		while i < j:
			if l[i] != l[j]:
				flag = 0
			if l[i] + 1 != l[i + 1] and l[i] != l[i + 1]:
				flag = 0
				break
			i += 1
			j -= 1
		if l[i] != 7:
			flag = 0
	if flag:
		print('yes')
	else:
		print('no')


T = int(input())
for i in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	mid = N // 2
	ctr = 1
	for i in range(0, mid + 1):
		if A[i] == ctr:
			ctr += 1
	if ctr < 8 or A[:] != A[::-1]:
		print('no')
	else:
		print('yes')


relist = [1, 2, 3, 4, 5, 6, 7]
t = int(input())
for i in range(t):
	a = int(input())
	list1 = list(map(int, input().split()))
	newlist = list(set(list1))
	revlist = list1[::-1]
	if newlist == relist and list1 == revlist:
		print('yes')
	else:
		print('no')


t = int(input())
for T in range(t):
	n = int(input())
	q = [int(x) for x in input().split()]
	prev = 1
	flag = 0
	if not q[0] == 1:
		print('no')
		continue
	for i in range(-(-n // 2)):
		if (q[i] == prev or q[i] == prev + 1) and q[i] == q[n - i - 1] and (q[i] > 0) and (q[i] < 8):
			pass
		else:
			flag = 1
			continue
		prev = q[i]
	if prev != 7:
		flag = 1
	if flag:
		print('no')
	else:
		print('yes')


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	left = 0
	right = len(A) - 1
	curr = 1
	while left <= right:
		if A[left] == A[right] and A[left] == curr:
			left += 1
			right -= 1
		else:
			curr += 1
			if A[left] == A[right] and A[left] == curr:
				left += 1
				right -= 1
			else:
				curr -= 1
				break
	if curr == 7:
		print('yes')
	else:
		print('no')


test = int(input())
while test:
	flag = 1
	n = int(input())
	elem = list(map(int, input().split()))
	(p1, p2) = (0, n - 1)
	if elem[0] != 1:
		flag = 0
	else:
		while p1 < p2:
			if elem[p1] != elem[p2]:
				flag = 0
				break
			if not (elem[p1] == elem[p1 + 1] or elem[p1] + 1 == elem[p1 + 1]):
				flag = 0
				break
			if elem[p1] > 7:
				flag = 0
				break
			p1 += 1
			p2 -= 1
	if elem[p1] != 7:
		flag = 0
	if flag == 1:
		print('yes')
	else:
		print('no')
	test -= 1


tkk = int(input())
for z in range(tkk):
	n = int(input())
	lt = list(map(int, input().split()))
	x = len(lt)
	t = 1
	f = 'yes'
	for i in range(x - 1):
		if lt[i] == t and lt[x - i - 1] == t:
			if lt[i + 1] != t:
				t += 1
				if t > 7:
					break
		else:
			f = 'no'
			break
	if t < 7:
		f = 'no'
	print(f)


t = int(input())
for t_ in range(t):
	n = int(input())
	mid = (n - 1) // 2
	arr = list(map(int, input().split()))
	valid = True
	if arr[0] != 1 or arr[mid] != 7:
		valid = False
	for i in range(0, mid):
		if arr[i + 1] != arr[i] and arr[i + 1] != arr[i] + 1:
			valid = False
			break
	if arr != list(reversed(arr)):
		valid = False
	if valid:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	t = 1
	for i in range(n):
		if arr[i] != arr[n - i - 1]:
			t = 0
			break
	if n % 2 == 0:
		m = n // 2
	else:
		m = n // 2 + 1
	for j in range(1, m):
		if arr[j - 1] + 1 == arr[j] or arr[j - 1] == arr[j]:
			pass
		else:
			t = 0
			break
	for k in range(n):
		if 1 <= arr[k] <= 7:
			pass
		else:
			t = 0
			break
	if t and len(set(arr)) == 7:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	a = int(input())
	a1 = list(map(int, input().split()))[:a]
	x = []
	y = [1, 2, 3, 4, 5, 6, 7]
	z = a1[::-1]
	for i in a1:
		if i not in x:
			x.append(i)
	if x == y and a1 == z:
		print('yes')
	else:
		print('no')


def distinct(a):
	b = []
	for i in a:
		if a not in b:
			b.append(i)
	return b
k = [1, 2, 3, 4, 5, 6, 7]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a == a[::-1] and set(distinct(a)) == set(k) and (sorted(a[:n // 2]) == a[:n // 2]):
		print('yes')
	else:
		print('no')


t = int(input())
required = '1234567'
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split(' ')))
	str_x = sorted(list(set(x)))
	str_x = [str(i) for i in str_x]
	str_x = ''.join(str_x)
	if str_x != required:
		print('no')
	else:
		flag = True
		for i in range(n // 2):
			if x[i] != x[n - i - 1]:
				flag = False
				break
			if i != 0 and x[i] - x[i - 1] not in [0, 1]:
				flag = False
				break
		print('yes' if flag else 'no')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	req = [1, 2, 3, 4, 5, 6, 7]
	(l, r) = (0, len(arr) - 1)
	flag = True
	for i in range(7):
		if arr[l] != req[i]:
			flag = False
			break
		while l <= r and arr[l] == req[i]:
			if arr[l] != arr[r]:
				flag = False
				break
			l += 1
			r -= 1
	print('yes') if flag else print('no')


testCases = int(input())
for testCase in range(testCases):
	n = int(input())
	a = list(map(int, input().split()))
	flag = True
	c = 1
	for i in range(n // 2 + 1):
		if a[i] == a[n - i - 1] and (a[i] == c or a[i] == c + 1):
			c = a[i]
		else:
			flag = False
			break
	if flag and a[n // 2] == 7:
		print('yes')
	else:
		print('no')


def validate_rainbow(arr):
	flag1 = True
	flag2 = True
	flag3 = True
	flag4 = True
	(i, n) = (0, len(arr) - 1)
	while i <= n:
		if arr[i] != arr[n]:
			flag1 = False
		i += 1
		n -= 1
	for i in range(1, len(arr) // 2):
		if arr[i] > arr[i + 1]:
			flag2 = False
	for i in range(len(arr)):
		if arr[i] < 1 or arr[i] > 7:
			flag3 = False
	if sum(set(arr)) != 28:
		flag4 = False
	if flag1 and flag2 and flag3 and flag4:
		return 'yes'
	return 'no'
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(validate_rainbow(arr))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(low, high, ans) = (0, n - 1, 'yes')
	if arr[low] != 1:
		ans = 'no'
	while low < high:
		if arr[low] != arr[low + 1] and arr[low + 1] != arr[low] + 1:
			ans = 'no'
			break
		if arr[low] != arr[high]:
			ans = 'no'
			break
		low += 1
		high -= 1
	if arr[low] != 7:
		ans = 'no'
	print(ans)


T = int(input())
for test_case in range(T):
	N = int(input())
	A = tuple((int(_) for _ in input().split()))
	strict_incr_decr = True
	seven_exists = A[(len(A) - 1) // 2] == 7
	prev = 1
	flip = False
	for a in A:
		if a > 7 or (not flip and a not in (prev, prev + 1)) or (flip and a not in (prev, prev - 1)):
			strict_incr_decr = False
			break
		prev = a
		if a == 7:
			flip = True
	print('yes' if all([A == A[::-1], strict_incr_decr, seven_exists]) else 'no')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mid = n // 2
	ctr = 1
	for i in range(0, mid + 1):
		if a[i] == ctr:
			ctr += 1
	if ctr < 8 or a[:] != a[::-1]:
		print('no')
	else:
		print('yes')


t = int(input())
x = [1, 2, 3, 4, 5, 6, 7]
for i in range(t):
	N = int(input())
	a = list(map(int, input().split()))
	rev = a[::-1]
	dup = set(a)
	if rev == a and list(dup) == x:
		print('yes')
	else:
		print('no')


x = [1, 2, 3, 4, 5, 6, 7]
for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	revli = li[::-1]
	dupli = set(li)
	if li == revli and list(dupli) == x:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	r = [1, 2, 3, 4, 5, 6, 7]
	N = int(input())
	li = list(map(int, input().split()))
	x = []
	for j in li:
		if j not in x:
			x.append(j)
	if li == li[::-1] and x == r:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	T = int(input())
	N = [int(i) for i in input().split()]
	A = 1
	for i in range(T // 2 + 1):
		if N[i] == A:
			A = A + 1
	print('no' if N != N[::-1] or A < 8 else 'yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p1 = 0
	p2 = n - 1
	flag = 1
	if a[p1] != 1:
		flag = 0
	else:
		while p1 < p2:
			if a[p1] != a[p2]:
				flag = 0
				break
			if a[p1] != a[p1 + 1] and a[p1] + 1 != a[p1 + 1]:
				flag = 0
				break
			p1 += 1
			p2 -= 1
		if a[p1] != 7:
			flag = 0
	if flag == 1:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	li = []
	for j in l:
		if j not in li:
			li.append(j)
	li.sort()
	print('yes' if li == [1, 2, 3, 4, 5, 6, 7] and l == l[::-1] else 'no')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if sum(set(arr)) != 28:
		print('no')
	elif arr[0:len(arr) // 2 + 1] != sorted(arr[0:len(arr) // 2 + 1]):
		print('no')
	elif arr == arr[::-1]:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	j = n - 1
	ans = True
	r = []
	while i <= j:
		if arr[i] == arr[j]:
			r.append(arr[i])
			i += 1
			j -= 1
		else:
			ans = False
			break
	if sorted(r) != r:
		ans = False
	for i in r:
		if i < 1 and i > 7:
			ans = False
			break
	for i in range(1, 8):
		if i not in r:
			ans = False
			break
	if ans:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	l = int(input())
	li = list(map(int, input().split()))[:l]
	a1 = []
	a2 = [1, 2, 3, 4, 5, 6, 7]
	a3 = li[::-1]
	for i in li:
		if i not in a1:
			a1.append(i)
	a1.sort()
	if a1 == a2 and li == a3:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 1
	mid = n // 2
	for i in range(mid + 1):
		if l[i] == c:
			c += 1
	if c < 8 or l[:] != l[::-1]:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	n = int(input())
	m = [int(i) for i in input().split()]
	cnt = 1
	mid = n // 2
	for i in range(mid + 1):
		if m[i] == cnt:
			cnt = cnt + 1
	if cnt < 8 or m != m[::-1]:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	k = int(input())
	rain = list(map(int, input().split()))
	h = 1
	f = 0
	for i in range(k - 1):
		if rain[i] == h and rain[k - i - 1] == h:
			if rain[i + 1] != h:
				h = h + 1
				if h > 7:
					break
		else:
			f = 1
			break
	if f == 0 and h >= 7:
		print('yes')
	else:
		print('no')


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if sum(set(l)) != 28:
		print('no')
	elif l[0:len(l) // 2 + 1] != sorted(l[0:len(l) // 2 + 1]):
		print('no')
	elif l == l[::-1]:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 1
	for i in range(n // 2 + 1):
		if arr[i] == count:
			count += 1
	if count < 8 or arr != arr[::-1]:
		print('no')
	else:
		print('yes')


def rb():
	try:
		num_elements = int(input())
		array = list(map(int, input().split()))
		master = 1
		flag = 0
		for i in range(num_elements // 2 + 1):
			if array[i] == array[num_elements - 1 - i] and (array[i] == master or array[i] == master + 1):
				master = array[i]
			else:
				flag = 1
				break
		if array[num_elements // 2] == 7 and flag == 0:
			print('yes')
		else:
			print('no')
	except Exception as e:
		pass
t = int(input())
for i in range(t):
	rb()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	v = 1
	c = 0
	for i in range(n - 1):
		if a[n - 1 - i] == v and a[i] == v:
			if a[i] != a[i + 1]:
				v += 1
				if v > 7:
					break
		else:
			c = 1
			break
	if c == 0 and v == 8:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 'no'
	tra = 1
	j = 1
	if arr == arr[::-1] and {1, 2, 3, 4, 5, 6, 7} == set(arr):
		ans = 'yes'
		for i in arr:
			if tra == 7:
				j = -1
			if i == tra:
				continue
			elif i == tra + j:
				tra += j
			else:
				ans = 'no'
				break
	print(ans)


for i in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	check = False
	for i in range(1, 8):
		if i not in list1:
			check = True
			break
	if check:
		print('no')
	else:
		check = True
		list2 = []
		for i in range(len(list1)):
			if list1[i] == 7:
				list2.insert(i, list1[i])
				break
			else:
				list2.insert(i, list1[i])
		for i in range(len(list2) - 1):
			if list2[i] <= list2[i + 1]:
				check = True
			else:
				check = False
				break
		if not check:
			print('no')
		else:
			for i in range(int(len(list1) / 2)):
				if list1[i] != list1[-i - 1]:
					check = False
					break
				else:
					check = True
			if check:
				print('yes')
			else:
				print('no')


for _ in range(int(input())):
	n = int(input())
	m = [int(i) for i in input().split()]
	z = 1
	for i in range(n // 2 + 1):
		if m[i] == z:
			z = z + 1
	print('no' if m != m[::-1] or z < 8 else 'yes')


tests = int(input())
for i in range(tests):
	length = int(input())
	arr = list(map(int, input().split()))
	ans = 'yes'
	if sum(set(arr)) != 28 or max(arr) != 7:
		ans = 'no'
	else:
		i = 0
		maximum = 1
		j = length - 1
		while i < j:
			if arr[i] != arr[j] or arr[i] < maximum:
				ans = 'no'
				break
			maximum = max(maximum, arr[i])
			i += 1
			j -= 1
	print(ans)


refList = [1, 2, 3, 4, 5, 6, 7]
t = int(input())
for i in range(t):
	a = int(input())
	list1 = list(map(int, input().split()))[:a]
	sevenInt = []
	revList = list1[::-1]
	for i in list1:
		if i not in sevenInt:
			sevenInt.append(i)
	if sevenInt == refList and list1 == revList:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = 0
	r = n - 1
	ans = True
	if a[l] != 1:
		ans = False
	else:
		while l < r:
			if a[l] != a[r]:
				ans = False
				break
			if a[l] != a[l + 1] and a[l] + 1 != a[l + 1]:
				ans = False
				break
			l += 1
			r -= 1
	if ans and (a[r] == 7 or a[l] == 7):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	flag = 0
	n = int(input())
	l1 = list(map(int, input().split()))
	if l1[::-1] != l1:
		print('no')
		flag = -1
	if flag != -1:
		d = {}
		for i in l1:
			d[i] = 1
		l2 = list(d.keys())
		temp = max(l2)
		for i in range(1, temp + 1):
			if i not in l2:
				print('no')
				flag = -1
				break
		for i in range(0, n // 2):
			if l1[i] > l1[i + 1]:
				print('no')
				flag = -1
		if l1[n // 2] != 7 and l1[n // 2 + 1] != 7 and (flag != -1):
			print('no')
			flag = -1
		if flag != -1:
			print('yes')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if 7 not in l:
		print('no')
		continue
	s = l.index(7)
	k = list(set(l[:s + 1]))
	t = [i for i in range(1, 8)]
	if k == t and l == l[::-1]:
		print('yes')
	else:
		print('no')


def calc(array):
	if max(array) == 7 and 1 in array:
		if array == array[::-1] and len(array) >= 13:
			for i in range(len(array)):
				if abs(array[i - 1] - array[i]) > 1:
					return 'no'
			return 'yes'
	return 'no'
n = int(input())
for i in range(n):
	length = int(input())
	ins = list(map(int, input().split(' ')))
	print(calc(ins))


x = int(input())
for i in range(x):
	y = int(input())
	lst = list(map(int, input().split()))
	c = []
	for j in lst:
		if j not in c:
			c.append(j)
	c.sort()
	print('yes' if c == [1, 2, 3, 4, 5, 6, 7] and lst == lst[::-1] else 'no')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = n - 1
	c = 1
	while l <= r:
		if arr[l] == arr[r] and arr[l] == c:
			l += 1
			r -= 1
		else:
			c += 1
			if arr[l] == arr[r] and arr[l] == c:
				l += 1
				r -= 1
			else:
				c -= 1
				break
	if c == 7:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	y = x // 2
	c = 1
	for i in range(y + 1):
		if a[i] == c:
			c += 1
	if c < 8 or a != a[::-1]:
		print('no')
	else:
		print('yes')


for _ in range(int(input())):
	i = int(input())
	j = list(map(int, input().split()))
	mid = i // 2
	count = 1
	for val in range(mid + 1):
		if j[val] == count:
			count += 1
	if count < 8 or j != j[::-1]:
		print('no')
	else:
		print('yes')


def solv(arr):
	for i in range(1, 8):
		if i not in arr:
			return 'no'
	mid = len(arr) // 2 if len(arr) % 2 == 0 else len(arr) // 2 + 1
	for i in range(1, mid):
		if arr[i] < arr[i - 1]:
			return 'no'
	for i in range(mid):
		if arr[i] != arr[-(i + 1)]:
			return 'no'
	return 'yes'
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solv(arr))


t = int(input())
case = 0
while case < t:
	n = int(input())
	arr = list(map(int, input().split()))
	p1 = 0
	p2 = n - 1
	flag = 1
	if arr[p1] != 1:
		flag = 0
	else:
		while p1 < p2:
			if arr[p1] != arr[p2]:
				flag = 0
				break
			if arr[p1] != arr[p1 + 1] and arr[p1] + 1 != arr[p1 + 1]:
				flag = 0
				break
			p1 += 1
			p2 -= 1
		if arr[p1] != 7:
			flag = 0
	if flag == 1:
		print('yes')
	else:
		print('no')
	case += 1


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	if sum(s) != 28:
		print('no')
	else:
		k = n // 2
		if l[0:k + 1] != sorted(l[0:k + 1]):
			print('no')
		elif l == l[::-1]:
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	s = int(input())
	l = list(map(int, input().split()))
	m = s // 2
	c = 1
	for i in range(m + 1):
		if l[i] == c:
			c += 1
	if c < 8 or l != l[::-1]:
		print('no')
	else:
		print('yes')


from sys import stdin
l = []
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	beg = 0
	end = n - 1
	curr = 1
	rainbow = True
	while beg <= end:
		if arr[beg] != arr[end]:
			rainbow = False
			break
		elif arr[beg] == curr + 1:
			curr += 1
			if curr > 7:
				rainbow = False
				break
		elif arr[beg] != curr:
			rainbow = False
			break
		beg += 1
		end -= 1
	if rainbow and curr == 7:
		l.append('yes')
	else:
		l.append('no')
for i in l:
	print(i)


t = int(input())
b = [1, 2, 3, 4, 5, 6, 7]
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sevenInt = []
	revList = a[::-1]
	for j in a:
		if j not in sevenInt:
			sevenInt.append(j)
	if sevenInt == b and a == revList:
		print('yes')
	else:
		print('no')


def check(L, n):
	if L == L[::-1] and L[0] == 1:
		for i in range(n // 2):
			if L[i + 1] == L[i] or L[i + 1] == L[i] + 1:
				continue
			else:
				return 'no'
		if L[i + 1] == 7:
			return 'yes'
	return 'no'
for T in range(int(input())):
	n = int(input())
	print(check(list(map(int, input().split())), n))


T = int(input())
for i in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	res = 'yes'
	if sum(set(l)) != 28 or max(l) != 7:
		res = 'no'
	else:
		left = 0
		reight = len(l) - 1
		maximam = 1
		while left < reight:
			if l[left] != l[reight] or l[left] < maximam:
				res = 'no'
				break
			maximam = max(l[left], maximam)
			left += 1
			reight -= 1
	print(res)


for i in range(int(input())):
	size = int(input())
	nums = list(map(int, input().split()))
	s = sorted(list(set(nums)))
	dup = []
	for j in range(len(nums) // 2 + 1):
		if nums[j] not in dup:
			dup.append(nums[j])
	if s == [1, 2, 3, 4, 5, 6, 7] and dup == [1, 2, 3, 4, 5, 6, 7]:
		flag = 1
	else:
		flag = 0
	if nums == nums[::-1] and flag == 1:
		print('yes')
	else:
		print('no')


t = int(input())
for t in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 'yes'
	if sum(set(l)) != 28 or max(l) != 7:
		ans = 'no'
	else:
		left = 0
		right = len(l) - 1
		maximum = 1
		while left < right:
			if l[left] != l[right] or l[left] < maximum:
				ans = 'no'
				break
			maximum = max(l[left], maximum)
			left += 1
			right -= 1
	print(ans)


for i in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	arr = [0] * 7
	j = 0
	number = 1
	pred = 0
	suc = N - 1
	res = ''
	while suc >= pred:
		if L[pred] == number and L[pred] == L[suc]:
			arr[L[pred] - 1] += 1
			pred += 1
			suc -= 1
		elif L[pred] != number and L[pred] == number + 1:
			number += 1
			if number > 7:
				res = 'no'
				break
		else:
			res = 'no'
			break
	if res == 'no' or min(arr) == 0:
		print('no')
	else:
		print('yes')