Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chef's canvas is N millimeters long and is initially all white. For simplicity, colors will be represented by an integer between 0 and 105. 0 indicates white. The picture he is envisioning is also N millimeters long and the ith millimeter consists purely of the color Ci. Unfortunately, his brush isn't fine enough to paint every millimeter one by one. The brush is 3 millimeters wide and so it can only paint three millimeters at a time with the same color. Painting over the same place completely replaces the color by the new one. Also, Chef has lots of bottles of paints of each color, so he will never run out of paint of any color.
Chef also doesn't want to ruin the edges of the canvas, so he doesn't want to paint any part beyond the painting. This means, for example, Chef cannot paint just the first millimeter of the canvas, or just the last two millimeters, etc.
Help Chef by telling him whether he can finish the painting or not with these restrictions.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N. The second line contains N space-separated integers C1, C2, ..., CN denoting the colors of Chef's painting.

-----Output-----
For each test case, output a single line containing either “Yes” or “No” (without quotes), denoting whether Chef can finish the painting or not.

-----Constraints-----
- 1 ≤ T ≤ 105
- 3 ≤ N ≤ 105
- The sum of the Ns over all the test cases in a single test file is ≤ 5×105
- 1 ≤ Ci ≤ 105

-----Example-----
Input:3
4
1 5 5 5
4
1 1 1 5
3
5 5 2
Output:Yes
Yes
No

-----Explanation-----
Example case 1. Chef's canvas initially contains the colors [0,0,0,0]. Chef can finish the painting by first painting the first three millimeters with color 1, so the colors become [1,1,1,0], and then the last three millimeters with color 5 so that it becomes [1,5,5,5].
Example case 2. Chef's canvas initially contains the colors [0,0,0,0]. Chef can finish the painting by first painting the last three millimeters by color 5 so the colors become [0,5,5,5], and then the first three millimeters by color 1 so it becomes [1,1,1,5].
Example case 3. In this test case, Chef can only paint the painting as a whole, so all parts must have the same color, and the task is impossible.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import sys
import math

def main(arr):
	for i in range(1, len(arr) - 1):
		if arr[i] == arr[i - 1] and arr[i] == arr[i + 1]:
			return 'Yes'
	return 'No'
for _ in range(int(input())):
	b = int(input())
	arr = list(map(int, input().split()))
	print(main(arr))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	count = 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			count += 1
			if count == 2:
				print('Yes')
				break
		else:
			count = 0
	else:
		print('No')


t = int(input())
while t:
	t -= 1
	n = int(input())
	ls = list(map(int, input().split()))
	k = 0
	for i in range(0, n - 2):
		if ls[i] == ls[i + 1] and ls[i + 1] == ls[i + 2]:
			k = 1
			break
	if k == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = [0] * n
	for i in range(n - 2):
		x[i] = x[i + 1] = x[i + 2] = l[i]
	for j in range(n - 1, 1, -1):
		if l[j] != x[j]:
			x[j] = x[j - 1] = x[j - 2] = l[j]
	if x == l:
		print('Yes')
	else:
		print('No')


def get_ans(ar, n):
	for i in range(n - 2):
		if ar[i] == ar[i + 1] == ar[i + 2]:
			return 'Yes'
	return 'No'
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	print(get_ans(ar, n))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = [0] * n
	for i in range(n - 2):
		x[i] = x[i + 1] = x[i + 2] = l[i]
	if x == l:
		print('Yes')
	elif n == 3:
		print('No')
	elif n == 4:
		if l[0] == l[1] and l[1] == l[2] or (l[-1] == l[-2] and l[-2] == l[-3]):
			print('Yes')
		else:
			print('No')
	else:
		for j in range(n - 1, 1, -1):
			if l[j] != x[j]:
				x[j] = x[j - 1] = x[j - 2] = l[j]
		if x == l:
			print('Yes')
		else:
			print('No')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	cou = 0
	for j in range(n - 2):
		a1 = l[j]
		a2 = l[j + 1]
		a3 = l[j + 2]
		if a1 == a2 and a2 == a3:
			flag = 1
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	for i in range(n - 2):
		if l[i] == l[i + 1] and l[i] == l[i + 2]:
			print('Yes')
			flag = 1
			break
	if flag == 0:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = 0
	for i in range(n - 2):
		l = a[i:i + 3]
		if len(set(l)) == 1:
			print('Yes')
			f = 1
			break
	if f == 0:
		print('No')


for _ in range(int(input())):
	a = int(input())
	arr = list(map(int, input().split()))
	prev = arr[0]
	count = 0
	f = 0
	for i in arr:
		if i == prev:
			count += 1
		else:
			prev = i
			count = 1
		if count >= 3:
			print('Yes')
			f = 1
			break
	if not f:
		print('No')


try:
	for _ in range(int(input())):
		n = int(input())
		lis = list(map(int, input().split()))
		flag = 0
		for i in range(n - 2):
			if lis[i] == lis[i + 1] == lis[i + 2]:
				flag = 1
				break
			else:
				continue
		if flag == 1:
			print('Yes')
		else:
			print('No')
except Exception:
	pass


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	for j in range(n - 2):
		if l[j] == l[j + 1] == l[j + 2]:
			flag = 1
			break
		else:
			continue
	if flag == 1:
		print('Yes')
	else:
		print('No')


for test_case in range(int(input())):
	n = int(input())
	canvas = list(map(int, input().split(' ')))
	threes = 0
	if n > 2:
		for i in range(n - 2):
			if canvas[i] == canvas[i + 1] and canvas[i + 1] == canvas[i + 2]:
				threes += 1
	if threes > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input().split(' ')
	arr = [int(i) for i in s]
	flag = 0
	for i in range(len(arr) - 2):
		if arr[i] == arr[i + 1] and arr[i + 1] == arr[i + 2]:
			flag = 1
			break
	if flag == 0:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n - 2):
		if a[i] == a[i + 1] and a[i] == a[i + 2]:
			ans = 1
	if ans == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	n = input()
	l = list(map(int, input().split()))
	i = 0
	z = 1
	while i < len(l) - 2:
		if len(set(l[i:i + 3])) == 1:
			z = 0
			break
		else:
			i += 1
	if z == 0:
		print('Yes')
	else:
		print('No')
	t -= 1


for j in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	c = 0
	for i in range(n - 2):
		if x[i] == x[i + 1] and x[i] == x[i + 2]:
			c = 1
			break
	if c == 1:
		print('Yes')
	else:
		print('No')


from collections import Counter
T = int(input())
for i in range(T):
	N = int(input())
	List = [int(x) for x in input().split()]
	Initial = List[0]
	a = 0
	count = 0
	for i in List:
		if Initial == i:
			count += 1
			if count >= 3:
				a = 1
				break
		if Initial != i:
			count = 1
		Initial = i
	if a == 1:
		print('Yes')
	else:
		print('No')


import sys
for i in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	c = list(map(int, sys.stdin.readline().split()))
	v = 0
	for j in range(n - 2):
		if c[j] == c[j + 1] == c[j + 2]:
			v += 1
			break
		else:
			pass
	if v == 1:
		sys.stdout.write('Yes\n')
	else:
		sys.stdout.write('No\n')


t = int(input())
for t1 in range(t):
	b = input()
	a = list(map(int, input().split()))
	x = 0
	f = 0
	while x < len(a) - 2:
		if a[x] == a[x + 1] and a[x + 1] == a[x + 2]:
			f = 1
			break
		x += 1
	if f == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	c = False
	for i in range(N - 2):
		if A[i] == A[i + 1] == A[i + 2]:
			c = True
			break
	if c == False:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	N = int(input())
	array = list(map(int, input().split()))
	possible = 'No'
	for i in range(N - 2):
		if array[i] == array[i + 1] and array[i] == array[i + 2]:
			possible = 'Yes'
			break
	print(possible)