In Chefland, types of ingredients are represented by integers and recipes are represented by sequences of ingredients that are used when cooking. One day, Chef found a recipe represented by a sequence $A_1, A_2, \ldots, A_N$ at his front door and he is wondering if this recipe was prepared by him.
Chef is a very picky person. He uses one ingredient jar for each type of ingredient and when he stops using a jar, he does not want to use it again later while preparing the same recipe, so ingredients of each type (which is used in his recipe) always appear as a contiguous subsequence. Chef is innovative, too, so he makes sure that in each of his recipes, the quantity of each ingredient (i.e. the number of occurrences of this type of ingredient) is unique ― distinct from the quantities of all other ingredients.
Determine whether Chef could have prepared the given recipe.

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

-----Output-----
For each test case, print a single line containing the string "YES" if the recipe could have been prepared by Chef or "NO" otherwise (without quotes).

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 10^3$
- $1 \le A_i \le 10^3$ for each valid $i$

-----Example Input-----
3
6
1 1 4 2 2 2
8
1 1 4 3 4 7 7 7
8
1 7 7 3 3 4 4 4

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

-----Explanation-----
Example case 1: For each ingredient type, its ingredient jar is used only once and the quantities of all ingredients are pairwise distinct. Hence, this recipe could have been prepared by Chef. 
Example case 2: The jar of ingredient $4$ is used twice in the recipe, so it was not prepared by Chef.

Difficulty: EASY

Solutions:
from collections import Counter

def chef(l):
	d = Counter(l)
	q = []
	for j in d:
		q.append(d[j])
	for h in range(len(q)):
		if q.count(q[h]) != 1:
			return False
		else:
			continue
	for j in range(0, len(d)):
		x = l[0]
		y = d[x]
		for k in range(0, y):
			if l[0] != x:
				return False
			else:
				l.remove(x)
				continue
	if len(l) == 0:
		return True
	else:
		return False
for i in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if chef(l) == True:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	N = int(input())
	L = list(map(int, input().split()))
	D = dict()
	U = []
	flag = True
	i = 0
	while i < N:
		if L[i] not in U:
			U.append(L[i])
			D[L[i]] = 1
		elif L[i] == L[i - 1]:
			D[L[i]] += 1
		else:
			flag = False
			break
		i += 1
	if flag:
		if len(set(D.values())) == len(D.values()):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	e = []
	c = 0
	u = []
	flag = 0
	A = list(map(int, input().split()))
	for i in range(0, n):
		if i == n - 1:
			if A[i] in u:
				print('NO')
				flag = 1
				break
			c += 1
			u.append(A[i])
			e.append(c)
		elif A[i] in u:
			print('NO')
			flag = 1
			break
		elif A[i] == A[i + 1]:
			c += 1
		elif A[i] != A[i + 1]:
			c += 1
			e.append(c)
			u.append(A[i])
			c = 0
	myset = set(e)
	if len(myset) != len(e) and flag != 1:
		print('NO')
	elif flag != 1:
		print('YES')


t = int(input())
while t:
	inc = {}
	ing = []
	flag = 0
	count = set()
	m = int(input())
	l = list(map(int, input().split()))
	for i in l:
		inc[i] = inc.get(i, 0) + 1
		if i in ing and ing[len(ing) - 1] != i:
			flag = 1
		elif i not in ing:
			ing.append(i)
	for i in inc.values():
		count.add(i)
	if flag == 1 or len(count) != len(inc.values()):
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	flag = 0
	dic = {}
	if len(r) > 1:
		for j in range(n):
			for k in range(j + 1, n, 1):
				if r[k] != r[j]:
					flag = 1
				elif r[k] == r[j] and flag == 1:
					flag = 2
					break
			if flag == 2:
				break
			else:
				flag = 0
	for j in range(n):
		dic[r[j]] = dic.get(r[j], 0) + 1
	s = set()
	for j in dic:
		s.add(dic[j])
	if len(s) < len(dic):
		flag = 2
	if flag == 2:
		print('NO')
	else:
		print('YES')


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(str, input().split()))
	F = []
	L = []
	CHEF = True
	for j in A:
		if L.count(j) == 0:
			if A.count(j) in F:
				CHEF = False
				break
			L.append(j)
			F.append(A.count(j))
			current = j
		elif current != j:
			CHEF = False
			break
	if CHEF == True:
		print('YES')
	else:
		print('NO')


t = input()
for c in range(0, int(t)):
	n = input()
	a = input().split()
	found = []
	chef = 1
	for x in range(0, int(n)):
		if x > 0:
			if a[x] != a[x - 1]:
				if a[x] in found:
					chef = 0
				else:
					found.append(a[x - 1])
	found.append(a[int(n) - 1])
	counts = []
	if chef == 1:
		for y in range(0, len(found)):
			temp = a.count(found[y])
			if temp in counts:
				print('NO')
				break
			else:
				counts.append(temp)
			if y == len(found) - 1:
				print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	i = list(map(int, input().split()))
	val = []
	key = []
	worked = True
	if n == 1:
		print('YES')
	else:
		for (num, char) in enumerate(i):
			if char not in key:
				key.append(char)
				val.append(i.count(char))
			elif char != i[num - 1]:
				worked = False
				break
		if len(val) != len(set(val)):
			worked = False
		if worked:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = {}
	ans = 'YES'
	prev = a[0]
	for i in range(n):
		if a[i] not in s:
			s[a[i]] = 1
			prev = a[i]
		elif a[i] in s and prev == a[i]:
			s[a[i]] += 1
		else:
			ans = 'NO'
			break
	b = list(s.values())
	c = set(b)
	if ans == 'YES':
		if len(b) != len(c):
			ans = 'NO'
		else:
			ans = 'YES'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ingredients = list(map(int, input().split(' ')))
	ls = [ingredients[0]]
	count = []
	index = []
	c = 1
	flag = 1
	for i in range(1, n):
		if ingredients[i] == ls[-1]:
			c = c + 1
		else:
			if ingredients[i] in ls:
				flag = 0
				break
			index.append(i)
			ls.append(ingredients[i])
			if c in count:
				flag = 0
				break
			count.append(c)
			c = 1
	if c in count or flag == 0:
		print('NO')
		continue
	print('YES')


import sys

def recipe(a, n):
	true = True
	frequency = []
	i = 0
	while i < n:
		ele = a[i]
		index = i
		while ele == a[index]:
			index += 1
			if index == n:
				break
		for k in range(index, n):
			if a[k] == a[i]:
				true = False
				break
		if true == False:
			break
		if a.count(a[i]) in frequency:
			true = False
			break
		else:
			frequency.append(a.count(a[i]))
		i = index
	if true:
		print('YES')
	else:
		print('NO')
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in sys.stdin.readline().split()]
	recipe(a, n)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	z = []
	w = 0
	for j in range(n):
		i = l[j]
		if len(a) == 0:
			a.append(i)
		elif a[-1] != i and i in a:
			print('NO')
			w = w + 1
			break
		elif a[-1] != i and i not in a:
			h = a.count(a[-1])
			if h in z:
				print('NO')
				w = w + 1
				break
			else:
				z.append(h)
				a.append(i)
		else:
			a.append(i)
		if j == n - 1:
			h = a.count(a[-1])
			if h in z:
				print('NO')
				w = w + 1
				break
	if w == 0:
		print('YES')


def solve(arr, n):
	mp = {}
	for i in range(n):
		if arr[i] not in mp:
			mp[arr[i]] = 1
		elif arr[i] in mp and arr[i] != arr[i - 1]:
			return 'NO'
		elif arr[i] in mp and arr[i] == arr[i - 1]:
			mp[arr[i]] += 1
	res = []
	for val in mp.values():
		if val not in res:
			res.append(val)
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	arr = [int(j) for j in input().split()]
	print(solve(arr, n))


def sol(n, l):
	(no, oc, m, k) = ({}, {}, l[0], 1)
	for i in range(1, n):
		if l[i] != m:
			if m in no or k in oc:
				return 'NO'
			else:
				(no[m], oc[k]) = (True, True)
			(m, k) = (l[i], 1)
		else:
			k += 1
	if m in no or k in oc:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(sol(n, l))


from collections import Counter
for x in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = Counter(l)
	c = list(c.values())
	flag = 1
	if len(c) != len(set(c)):
		flag = 0
	if flag != 0:
		u = []
		for i in range(n):
			if l[i] in u:
				flag = 0
				break
			if i + 1 < n and l[i] != l[i + 1]:
				u.append(l[i])
	if flag == 1:
		print('YES')
	else:
		print('NO')


import sys
cases = int(sys.stdin.readline().rstrip())
for case in range(cases):
	N = int(sys.stdin.readline().rstrip())
	p = list(map(int, sys.stdin.readline().rstrip().split(' ')))
	freq = [0] * 1001
	freq[p[0]] += 1
	error = False
	for i in range(1, len(p)):
		if freq[p[i]] > 0 and p[i - 1] != p[i]:
			error = True
			break
		else:
			freq[p[i]] += 1
	if error:
		print('NO')
	else:
		ms = []
		error = False
		for q in freq:
			if q in ms and q != 0:
				error = True
				break
			ms.append(q)
		if error:
			print('NO')
		else:
			print('YES')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(d, i, r) = ({}, 0, 1)
	while i < n:
		if a[i] not in d:
			d[a[i]] = 1
		elif a[i] == a[i - 1]:
			d[a[i]] += 1
		else:
			r = 0
		i += 1
	freq = [j for j in d.values()]
	if len(freq) != len(set(freq)):
		r = 0
	print('YES' if r else 'NO')


from collections import Counter
for _ in range(int(input())):
	k = int(input())
	arr = list(map(int, input().split()))
	c = Counter(arr)
	s = set()
	flag = 1
	s = []
	for i in range(1, len(arr)):
		if arr[i - 1] != arr[i]:
			if arr[i - 1] not in s:
				s.append(arr[i - 1])
			else:
				flag = 0
				break
	s.append(arr[k - 1])
	if flag:
		counts = []
		for y in range(0, len(s)):
			temp = arr.count(s[y])
			if temp in counts:
				print('NO')
				flag = 0
				break
			else:
				counts.append(temp)
			if y == len(s) - 1:
				print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	con = []
	count = 1
	c = []
	i = 0
	while i < n:
		while i < n - 1 and arr[i] == arr[i + 1]:
			i += 1
			count += 1
		if arr[i] in con or count in c:
			break
		con.append(arr[i])
		c.append(count)
		i += 1
		count = 1
	if i == n:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	i = 0
	flag = True
	while i < n:
		if arr[i] not in d:
			count = 1
			while i < n - 1 and arr[i] == arr[i + 1]:
				count += 1
				i += 1
			d[arr[i]] = count
		else:
			flag = False
			break
		i += 1
	if flag == False:
		print('NO')
	else:
		t = list(d.values())
		if len(t) == len(set(t)):
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	N = int(input())
	Arr = list(map(int, input().split()))
	flag = 0
	unique = list(set(Arr))
	count = []
	for i in unique:
		count.append(Arr.count(i))
	count_new = list(set(count))
	if len(count_new) != len(count):
		print('NO')
	else:
		flag = 0
		for i in unique:
			j = 0
			pos = []
			while j < N:
				if Arr[j] == i:
					pos.append(j)
				if len(pos) >= 2:
					if pos[-1] - pos[-2] > 1:
						flag = 1
						break
				j = j + 1
			if flag == 1:
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')


T = int(input())
while T:
	N = input()
	N = int(N)
	A = list(map(int, input().strip().split()))[:N]
	C = {}
	D = []
	D.append(A[0])
	for i in range(N):
		if A[i] not in C.keys():
			C[A[i]] = A.count(A[i])
	res = True
	for i in range(1, N):
		if A[i] != A[i - 1] and A[i] in D:
			res = False
			break
		if list(C.values()).count(A.count(A[i])) > 1:
			res = False
			break
		if A[i] not in D:
			D.append(A[i])
	if res is True:
		print('YES')
	else:
		print('NO')
	T -= 1


for _ in range(int(input())):
	n = int(input())
	l = input().split()
	f = []
	e = []
	c = 0
	flag = 0
	for i in range(0, n):
		if i == n - 1:
			if l[i] not in e:
				e.append(l[i])
				f.append(c + 1)
			else:
				print('NO')
				flag = 1
				break
		else:
			if l[i] != l[i + 1]:
				f.append(c + 1)
				c = 0
				if l[i] in e:
					print('NO')
					flag = 1
					break
				else:
					e.append(l[i])
			if l[i] == l[i + 1]:
				c += 1
	if flag == 0:
		ff = 0
		for i in f:
			if f.count(i) > 1:
				print('NO')
				ff = 1
				break
		if ff == 0:
			print('YES')


for i in range(int(input())):
	n = input()
	armain = list(map(int, input().split()))
	types = {}
	for elem in armain:
		if elem not in types:
			types[elem] = 0
	yesno = True
	for curin in range(len(armain)):
		if types[armain[curin]] == 1:
			yesno = False
			break
		if len(armain) > curin + 1 and armain[curin + 1] != armain[curin]:
			types[armain[curin]] = 1
	if yesno == True:
		for xyz in types:
			types[xyz] = 0
		for curin in armain:
			types[curin] += 1
		duplist = []
		for val in types.values():
			if val in duplist:
				yesno = False
				break
			duplist.append(val)
	print('YES' if yesno else 'NO')


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	k = x[0]
	count = []
	c = 0
	flag = 0
	y = []
	for j in range(n):
		if j == n - 1:
			if x[j] in y:
				print('NO')
				flag = 1
				break
			c += 1
			if c in count:
				print('NO')
				flag = 1
				break
			count.append(c)
		elif k == x[j] and x[j] not in y and (x[j + 1] == x[j]):
			c += 1
		elif x[j] in y:
			print('NO')
			flag = 1
			break
		elif x[j + 1] != k:
			c += 1
			if c in count:
				print('NO')
				flag = 1
				break
			count.append(c)
			c = 0
			y.append(k)
			k = x[j + 1]
	if flag == 0:
		print('YES')


t = int(input())
for t in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	d = []
	count = []
	s = set(arr)
	for a in s:
		count.append(arr.count(a))
	d.append(arr[0])
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			d.append(arr[i])
	if len(d) == len(set(d)) and len(count) == len(set(count)):
		print('YES')
	else:
		print('NO')


a = int(input())
for _ in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = set(c)
	e = set()
	for i in d:
		e.add(c.count(i))
	done = True
	for i in range(len(c) - 1):
		if c[i] != c[i + 1] and c[i] in c[i + 1:]:
			done = False
			break
	if len(d) != len(e) or not done:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	n = int(input())
	l1 = list(map(int, input().split()))
	a = 0
	h = 1
	l = []
	for i in range(n - 1):
		if l1[i] != l1[i + 1]:
			for j in range(i + 1, n):
				if l1[j] == l1[i]:
					a = 1
					break
				else:
					pass
			l = l + [h]
			h = 1
		else:
			h = h + 1
	l = l + [h]
	c = 0
	for k in range(len(l) - 1):
		for j in range(k + 1, len(l)):
			if l[k] == l[j]:
				c = 1
	if a == 1 or c == 1:
		print('NO')
	else:
		print('YES')
	t = t - 1


for i in range(int(input())):
	numero_ingredientes = int(input())
	ingredientes = list(map(int, input().split()))
	unicos = set(ingredientes)
	repeticiones = []
	usados = []
	check_1 = True
	check_2 = True
	for i in unicos:
		repeticiones.append(ingredientes.count(i))
	if len(repeticiones) > len(set(repeticiones)):
		check_1 = False
	for i in range(0, numero_ingredientes - 1):
		if ingredientes[i] != ingredientes[i + 1]:
			usados.append(ingredientes[i])
			if ingredientes[i + 1] in usados:
				check_2 = False
	if not check_1 or not check_2:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	val = [int(x) for x in input().split()]
	ing = [val[0]]
	count = []
	c = 1
	prev = val[0]
	ans = 'YES'
	for i in val[1:]:
		if prev == i:
			c += 1
		elif c not in count and i not in ing:
			count.append(c)
			c = 1
			prev = i
			ing.append(prev)
		else:
			ans = 'NO'
			break
	if c in count:
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	m = {}
	for i in a:
		if i not in m:
			m[i] = 1
		else:
			m[i] += 1
	s = set()
	for i in m:
		s.add(m[i])
	if len(s) != len(m):
		print('NO')
		continue
	tt = 1
	for i in range(n):
		flag = 1
		for j in range(i + 1, n):
			if a[i] != a[j]:
				flag = 0
			if flag == 0 and a[i] == a[j]:
				print('NO')
				tt = 0
				break
		if tt == 0:
			break
	if tt == 1:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = {}
	flag = 0
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = [i, 1]
		elif d[a[i]][0] == i - 1:
			d[a[i]][0] = i
			d[a[i]][1] += 1
		else:
			flag = i
			break
	l = [i[1] for i in d.values()]
	if flag == 0 and len(set(l)) == len(l):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	state = 0
	l1 = list()
	l2 = list()
	count = 1
	for i in range(n):
		if l[i] not in l1:
			l1.append(l[i])
			if i != 0:
				if count not in l2:
					l2.append(count)
					count = 1
				else:
					state = 10
					break
		elif l[i] == l[i - 1]:
			count += 1
		else:
			state = 10
			break
	if count in l2:
		state = 10
	if state == 0:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	ans = None
	used = defaultdict(lambda : 0)
	used[A[0]] = 1
	for i in range(1, N):
		if A[i - 1] == A[i]:
			used[A[i]] += 1
		elif A[i] not in used.keys():
			used[A[i]] += 1
		else:
			ans = 'NO'
			break
	if len(set(used.values())) != len(used.values()):
		ans = 'NO'
	print('NO' if ans == 'NO' else 'YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = []
	jars = [arr[0]]
	prev = arr[0]
	curr_count = 1
	flag = True
	for a in arr[1:]:
		if a != prev:
			if a in jars or curr_count in count:
				flag = False
				break
			jars.append(a)
			count.append(curr_count)
			curr_count = 1
		else:
			curr_count += 1
		prev = a
	if curr_count in count:
		flag = False
	print('YES' if flag else 'NO')


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	p = set(a)
	k = list(p)
	l = []
	flag = 0
	prev = a[0]
	y = ['F'] * 1001
	for i in range(len(k)):
		l.append(a.count(k[i]))
	if len(set(l)) == len(p):
		for z in a:
			if y[z] == 'T' and prev != z:
				flag = 1
				break
			else:
				y[z] = 'T'
			prev = z
	else:
		flag = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	a = int(input())
	l = list(map(int, input().split()))
	c = []
	b = []
	count = 0
	mark = 0
	for i in range(a):
		if l[i] not in b:
			b.append(l[i])
			if count in c:
				mark = 1
				break
			else:
				c.append(count)
			count = 0
			count += 1
		elif b[i - 1] != l[i]:
			mark = 1
			break
		else:
			b.append(l[i])
			count += 1
	if count in c:
		mark = 1
	if mark == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	ing = list(map(int, input().split()))
	ing.append(ing[-1])
	count = {}
	elem = {}
	prepared = True
	m = 0
	for x in range(n - 1):
		m += 1
		if ing[x] != ing[x + 1]:
			if ing[x] in elem:
				prepared = False
				break
			elif m in count:
				prepared = False
				break
			count[m] = True
			elem[ing[x]] = True
			m = 0
	if ing[-1] in elem:
		prepared = False
	if m + 1 in count:
		prepared = False
	if prepared is True:
		print('YES')
	else:
		print('NO')


def recp():
	lent = int(input())
	l = list(map(lambda x: int(x), input().split()))
	d = {}
	for i in range(lent):
		if l[i] in d:
			if l[i] == l[i - 1]:
				d[l[i]] += 1
			else:
				return 'NO'
		else:
			d[l[i]] = 1
	count = set(d.values())
	if len(count) == len(d):
		return 'YES'
	else:
		return 'NO'
for T in range(int(input())):
	ans = recp()
	print(ans)


z = int(input())
for i in range(z):
	f = int(input())
	k1 = input()
	k = k1.split()
	l = list(map(int, k))
	counter = []
	emp = []
	m = ''
	for j in l:
		counter.append(l.count(j))
	set_l = set(l)
	if len(set(counter)) != len(set_l):
		print('NO')
	else:
		out = 'YES'
		sep_count = 0
		temp = [x for x in l]
		for i in range(len(temp) - 1):
			if temp[i] != temp[i + 1]:
				l.insert(i + 1, 'sep')
				sep_count += 1
		if sep_count != len(set_l) - 1:
			out = 'NO'
		print(out)


for t in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	d = {}
	x = []
	for i in range(a):
		if l[i] not in d:
			d[l[i]] = l.count(l[i])
	y = list(d.values())
	for j in range(1, len(l)):
		if l[j] != l[j - 1]:
			x.append(l[j])
	x.append(l[0])
	if len(set(x)) == len(x) and len(y) == len(set(y)):
		print('YES')
	else:
		print('NO')


t = int(input())
for tesCase in range(t):
	n = int(input())
	string = input()
	lst = string.split()
	ulst = sorted(set(lst))
	len_lst = []
	lstemp = []
	for i in range(len(ulst)):
		len_lst.append(lst.count(ulst[i]))
	lst.append(' ')
	for i in range(len(lst) - 1):
		if lst[i] != lst[i + 1]:
			lstemp.append(lst[i])
	if sorted(len_lst) == sorted(set(len_lst)) and sorted(lstemp) == sorted(set(lstemp)):
		print('YES')
	else:
		print('NO')


def test(i, lst):
	ind = lst.index(i)
	x = True
	for j in range(lst.count(i)):
		x = x and lst[ind] == lst[ind + j]
	return x
T = int(input())
for _ in range(T):
	N = int(input())
	lst = list(map(int, input().split()))
	count = []
	ls = set(lst)
	l = len(ls)
	for i in ls:
		count.append(lst.count(i))
	check = [test(i, lst) for i in ls]
	if len(count) == len(set(count)) and all(check):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	numbers = input().split()
	occurrence = {}
	dic = {}
	remembered = []
	for i in range(N):
		numbers[i] = int(numbers[i])
		occurrence[numbers[i]] = 0
	for i in range(N):
		occurrence[numbers[i]] += 1
	for i in range(N):
		count = 0
		if numbers[i] in remembered:
			continue
		remembered.append(numbers[i])
		for j in range(i, N, 1):
			if numbers[j] == numbers[i]:
				count += 1
			else:
				break
		dic[numbers[i]] = count
	next = False
	for key in dic:
		if dic[key] != occurrence[key]:
			print('NO')
			next = True
			break
	if next == False:
		remembered.clear()
		for key in dic:
			remembered.append(dic[key])
		remembered.sort()
		skip = False
		for i in range(len(remembered) - 1):
			if remembered[i] == remembered[i + 1]:
				print('NO')
				skip = True
				break
		if skip == False:
			print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	unique = set(A)
	count = Counter(A)
	position = []
	position.append(A[0])
	for i in range(1, len(A)):
		if A[i] != A[i - 1]:
			position.append(A[i])
	unique_count = set(list(count.values()))
	if len(unique_count) == len(list(count.values())) and len(set(position)) == len(position):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	c = 0
	for i in range(len(a)):
		x = a[i]
		if x not in d:
			d[x] = 1
		elif a[i - 1] == x:
			d[x] += 1
		else:
			c = 1
	b = [x for x in d.values()]
	if c == 1 or len(set(b)) != len(b):
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(0, a):
	b = int(input())
	c = list(map(int, input().split()))
	n = [0 for k in range(0, 1000)]
	f1 = [0 for k in range(0, 1000)]
	f2 = [0 for k in range(0, 1000)]
	for l in range(0, b):
		f1[c[l] - 1] += 1
	bo = True
	for l in range(0, 1000):
		if f1[l] > 0:
			f2[f1[l]] += 1
			if f2[f1[l]] > 1:
				bo = False
				break
	if bo:
		j = 1
		n[c[0] - 1] = 1
		while j < b:
			if c[j] == c[j - 1]:
				j += 1
			elif c[j] != c[j - 1] and n[c[j] - 1] != 1:
				n[c[j] - 1] = 1
				j += 1
			else:
				print('NO')
				break
		if j == b:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	new = {}
	for i in L:
		if i in new.keys():
			if i != list(new.keys())[-1]:
				print('NO')
				break
			new[i] += 1
		else:
			new[i] = 0
	else:
		print('YES' if len(new.values()) == len(set(new.values())) else 'NO')


from collections import Counter
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	count = dict(Counter(A))
	count_k = list(count.values())
	count_ks = set(count_k)
	c = 0
	if len(count_k) == len(count_ks):
		for i in range(1, N):
			if A[i - 1] != A[i] and A[i - 1] in A[i:]:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	ingredients = list(map(int, input().split(' ')))
	prev = 0
	ing_counts = {}
	flag = False
	for ing in ingredients:
		curr = ing
		if prev == curr:
			ing_counts[curr] += 1
		elif curr in ing_counts.keys():
			print('NO')
			flag = True
			break
		else:
			ing_counts[curr] = 1
		prev = curr
	if not flag:
		counts = ing_counts.values()
		if len(counts) == len(set(counts)):
			print('YES')
		else:
			print('NO')


for x in range(int(input())):
	_ = input()
	(number, count) = ([], [])
	recipe = list(map(int, input().split(' ')))
	flag = 1
	for i in range(len(recipe)):
		if recipe[i] in number and recipe[i - 1] != recipe[i]:
			flag = 0
			break
		if recipe[i] in number and recipe[i - 1] == recipe[i]:
			continue
		if not recipe[i] in number:
			number.append(recipe[i])
			count.append(recipe.count(recipe[i]))
	if len(list(count)) != len(set(count)):
		flag = 0
	print('YES') if flag == 1 else print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a
	c = a
	b = list(dict.fromkeys(b))
	d = []
	dict1 = {}
	e = []
	for i in range(len(c) - 1):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	for j in a:
		dict1[j] = a.count(j)
	v = dict1.values()
	f = list(dict.fromkeys(v))
	if list(v) == f:
		if b == d:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ing = [l[0]]
	count = []
	c = 1
	d = l[0]
	ans = 'YES'
	for i in l[1:]:
		if d == i:
			c += 1
		elif c not in count and i not in ing:
			count.append(c)
			c = 1
			d = i
			ing.append(d)
		else:
			ans = 'NO'
			break
	if c in count:
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	b = 'YES'
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	a = []
	for i in s:
		a = a + [l.count(i)]
	if sorted(a) == sorted(set(a)):
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				continue
			else:
				for j in l[i + 1:n]:
					if j == l[i]:
						b = 'NO'
						break
	else:
		b = 'NO'
	print(b)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	c = 0
	l1 = []
	for x in s:
		l1.append(l.count(x))
	if len(l1) != len(set(l1)):
		c = 1
	for i in range(len(l) - 1):
		if l[i] in s:
			if l[i] != l[i + 1]:
				s.remove(l[i])
		else:
			c = 1
	if l[n - 1] not in s:
		c = 1
	if c == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for abcd in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = Counter(a)
	i = 0
	ans = 'YES'
	vals = []
	for indx in x:
		vals.append(x[indx])
	if len(set(vals)) != len(vals):
		print('NO')
		continue
	while i < n:
		count = x[a[i]]
		for j in range(i, i + count):
			if a[j] != a[i]:
				ans = 'NO'
				break
		if ans == 'NO':
			break
		i += count
	print(ans)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	count = Counter(A)
	countList = list(count.values())
	f = 1
	if len(countList) != len(set(countList)):
		f = 0
	if f != 0:
		u = []
		for j in range(n):
			if A[j] in u:
				f = 0
				break
			if j + 1 < n and A[j] != A[j + 1]:
				u.append(A[j])
	if f == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	r = None
	count = 0
	f = 1
	for j in range(len(a)):
		if r == None:
			r = a[j]
		elif a[j] not in b:
			if a[j] == r:
				count += 1
			elif count in c:
				f = 0
				break
			else:
				c.append(count)
				b.append(r)
				r = a[j]
				count = 0
		else:
			f = 0
			break
	if count in c:
		f = 0
	if f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = list(set(l))
	l3 = []
	d = 0
	for _ in l2:
		c = l.count(_)
		l3.append(c)
	for _ in range(n - 1):
		if l[_] != l[_ + 1] and l[_] in l[_ + 1:n]:
			d += 1
	for _ in l3:
		if l3.count(_) != 1:
			d += 1
	if d == 0:
		print('YES')
	else:
		print('NO')


def main(arr):
	has = {}
	ctr = 1
	x = set()
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			if arr[i] in has:
				return 'NO'
			else:
				has[arr[i - 1]] = ctr
				if ctr in x:
					return 'NO'
				else:
					x.add(ctr)
				ctr = 1
		else:
			ctr += 1
	if ctr in x:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	print(main(arr))


t = int(input())
for i in range(t):
	n = int(input())
	recipe = list(map(int, input().split()))
	recipe_set = set(recipe)
	d = []
	count = 1
	for mm in range(1, n):
		if recipe[mm] == recipe[mm - 1]:
			count += 1
		else:
			d.append(count)
			count = 1
	d.append(count)
	counter_set = []
	for kkk in recipe_set:
		counter_set.append(recipe.count(kkk))
	if len(counter_set) == len(d):
		if len(set(counter_set)) == len(counter_set):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = int(input())
	l = [int(x) for x in input().split()]
	lr = l[::-1]
	sl = set(l)
	cnt = set()
	fl = 1
	for i in sl:
		c = l.count(i)
		if c in cnt:
			print('NO')
			break
		else:
			cnt.add(c)
	else:
		for i in sl:
			ind1 = l.index(i)
			ind2 = n - lr.index(i)
			if ind2 - ind1 != l.count(i):
				print('NO')
				break
		else:
			print('YES')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	l = []
	a = []
	i = 0
	t = 0
	a.append(lis[0])
	l.append(lis.count(lis[0]))
	while i < len(lis) - 1:
		if lis[i] != lis[i + 1]:
			if lis[i + 1] not in a:
				a.append(lis[i + 1])
				l.append(lis.count(lis[i + 1]))
			else:
				t = 1
				break
		i = i + 1
	l.sort()
	for j in range(len(l) - 1):
		if l[j] == l[j + 1]:
			t = 1
			break
	if t == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	count = []
	check = []
	for i in s:
		count.append(arr.count(i))
	check.append(arr[0])
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			check.append(arr[i])
	if len(check) == len(set(check)) and len(count) == len(set(count)):
		print('YES')
	else:
		print('NO')


def solve():
	s = int(input())
	l = list(map(int, input().split()))
	d = {}
	prev = 0
	for i in l:
		if prev != i:
			prev = i
			if i in d:
				print('NO')
				return
			else:
				d[i] = 1
		else:
			d[i] += 1
	if len(d.values()) != len(set(d.values())):
		print('NO')
	else:
		print('YES')
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if l[i] not in d:
			d[l[i]] = 1
		elif l[i - 1] == l[i]:
			d[l[i]] += 1
		else:
			print('NO')
			break
	else:
		l2 = [x for x in d.values()]
		if len(set(l2)) == len(l2):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	u = []
	t = []
	ut = []
	qw = []
	c = 0
	for i in l:
		if i not in u:
			u.append(i)
			t.append(l.count(i))
	for i in t:
		if i not in ut:
			ut.append(i)
	for i in l:
		if i not in qw or qw[-1] == i:
			qw.append(i)
		else:
			print('NO')
			c = 1
			break
	if c == 0 and len(ut) == len(t):
		print('YES')
	elif c == 0:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	d = {}
	ans = 0
	curr = a[0]
	d[a[0]] = 0
	for i in a:
		if i != curr and i in d.keys():
			ans = 1
			break
		elif i == curr:
			d[i] += 1
		else:
			curr = i
			d[i] = 1
		s = []
	for i in d.values():
		if i in s:
			ans = 1
			break
		s.append(i)
	if ans == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	ings = list(map(int, input().split()))
	di_ings = {}
	last = 0
	possible = True
	for ing in ings:
		if ing in di_ings:
			if last == ing:
				di_ings[ing] += 1
			else:
				possible = False
				break
		else:
			di_ings[ing] = 1
			last = ing
	if possible and len(set(di_ings)) == len(set(di_ings.values())):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	x = L[0]
	X = set({L[0]})
	Y = [L.count(L[0])]
	flag = True
	for i in L:
		if i == x:
			pass
		elif i in X:
			flag = False
			break
		else:
			X.add(i)
			Y.append(L.count(i))
			x = i
	for j in Y:
		if Y.count(j) > 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	inp = list(map(int, input().split()))
	ing = [inp[0]]
	count = []
	last = inp[0]
	ans = 'YES'
	cnt = 1
	for i in range(1, n):
		if last == inp[i]:
			cnt += 1
		elif cnt not in count and inp[i] not in ing:
			count.append(cnt)
			cnt = 1
			last = inp[i]
			ing.append(last)
		else:
			ans = 'NO'
			break
	if cnt in count:
		ans = 'NO'
	print(ans)


for i in range(int(input())):
	n = int(input())
	rec = list(map(int, input().split()))
	set_rec = set(rec)
	count = []
	check = []
	for i in set_rec:
		count.append(rec.count(i))
	check.append(rec[0])
	for i in range(1, n):
		if rec[i] != rec[i - 1]:
			check.append(rec[i])
	if len(check) == len(set(check)) and len(count) == len(set(count)):
		print('YES')
	else:
		print('NO')


t = int(input())

def joe(joe_list):
	joe_dict = {}
	for i in joe_list:
		if i not in joe_dict.keys():
			joe_dict[i] = 0
		joe_dict[i] += 1
	joe_set = {1}
	joe_set.remove(1)
	for x in joe_dict.values():
		joe_set.add(x)
	if len(joe_set) != len(joe_dict.values()):
		return 'NO'
	in_a_row_list = [joe_list[0]]
	for i in range(1, len(joe_list)):
		if joe_list[i] != joe_list[i - 1]:
			if joe_list[i] in in_a_row_list:
				return 'NO'
			in_a_row_list.append(joe_list[i])
	return 'YES'
for tc in range(t):
	N = int(input())
	joe_list = list(map(int, input().split()))
	print(joe(joe_list))


j = int(input())
for z in range(j):
	size = int(input())
	recipe = list(map(int, input().split()))
	statement = 'YES'
	pointer = recipe[0]
	used = {pointer: 1}
	arr1 = [pointer]
	arr2 = []
	for i in range(1, len(recipe)):
		if recipe[i] == pointer:
			used[pointer] = used[pointer] + 1
		else:
			pointer = recipe[i]
			used.update({pointer: 1})
			arr1.append(pointer)
	for i in used:
		if arr1.count(i) != 1:
			statement = 'NO'
			break
		arr2.append(used[i])
	for i in arr2:
		if arr2.count(i) != 1:
			statement = 'NO'
			break
	print(statement)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	ans = 'YES'
	dic = {}
	prev = ''
	for j in l:
		if prev != j:
			a.append(j)
			prev = j
	for m in a:
		if a.count(m) > 1:
			ans = 'NO'
	for k in a:
		dic[k] = 0
	for o in l:
		dic[o] += 1
	vals = [*dic.values()]
	for i in vals:
		if vals.count(i) > 1:
			ans = 'NO'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = set(l)
	l1 = []
	l2 = []
	c = 1
	for i in range(0, n - 1):
		if l[i] != l[i + 1]:
			l1.append(l[i])
	l1.append(l[-1])
	for j in a:
		b = l.count(j)
		if b not in l2:
			l2.append(b)
		else:
			c = 0
			break
	if c == 1:
		if len(a) != len(l1):
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	ingrediants = list(map(int, input().split(' ')))
	ingrediants_dict = dict()
	for ele in ingrediants:
		if ele in ingrediants_dict:
			value = ingrediants_dict[ele]
			ingrediants_dict[ele] = value + 1
		else:
			ingrediants_dict[ele] = 1
	ingrediants_num = list(ingrediants_dict.values())
	Chef_recipe = 0
	if len(ingrediants_num) == len(set(ingrediants_num)):
		Chef_recipe = 1
	if Chef_recipe == 1:
		for key in ingrediants_dict:
			firstindex = ingrediants.index(key)
			for j in range(ingrediants_dict[key]):
				if ingrediants[firstindex + j] != key:
					Chef_recipe = 0
					break
			if Chef_recipe == 0:
				break
		if Chef_recipe == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
t = int(input())
for fhurf in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a
	d = {}
	ans = 'YES'
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = 1
		elif a[i] == a[i - 1]:
			d[a[i]] += 1
		else:
			ans = 'NO'
			break
	a = []
	for x in d:
		a.append(d[x])
	if len(set(a)) != len(a):
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	d = {}
	d[l[0]] = 1
	flag = True
	for i in range(1, n):
		if l[i] not in d:
			d[l[i]] = 1
		elif l[i - 1] == l[i]:
			d[l[i]] += 1
		else:
			flag = False
			break
	if flag:
		s = []
		for i in d:
			s.append(d[i])
		if len(s) == len(list(set(s))):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
from itertools import repeat
for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = [*Counter(a)]
	ans = 'YES'
	c = []
	for x in s:
		if a.count(x) in c:
			ans = 'NO'
			break
		c.append(a.count(x))
	if ans == 'YES':
		test = []
		for x in range(len(s)):
			test.extend(repeat(s[x], c[x]))
		if test != a:
			ans = 'NO'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	ingredients = []
	groups = []
	j = 0
	itt = 0
	decision = 0
	while itt < n:
		if j == n:
			break
		num = lis[j]
		g_count = 0
		while lis[j] == num:
			g_count = g_count + 1
			j = j + 1
			if j == n:
				break
		if g_count in groups:
			decision = 1
			break
		else:
			groups.append(g_count)
		if num in ingredients:
			decision = 1
			break
		else:
			ingredients.append(num)
		itt = itt + 1
	if decision == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	d = {}
	ans = 'YES'
	cur = ''
	for i in a:
		if i != cur:
			if i in d:
				ans = 'NO'
				break
			else:
				cur = i
		d[i] = d.get(i, 0) + 1
	if ans == 'YES':
		e = d.values()
		if len(e) != len(set(e)):
			ans = 'NO'
	print(ans)


import collections
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = collections.defaultdict(int)
	f = 1
	for i in l:
		if d[i] == 0:
			d[i] = 1
		elif last != i:
			f = 0
			break
		else:
			d[i] += 1
		last = i
	ans = set()
	for i in d:
		if d[i] in ans:
			f = 0
			break
		ans.add(d[i])
	if f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	re = list(map(int, input().split()))
	li = []
	ct = []
	cnt = 0
	ans = 'YES'
	for i in range(n):
		prev = re[i - 1]
		cur = re[i]
		if i == 0:
			prev = cur
		if prev != cur and cur in li:
			ans = 'NO'
		li.append(cur)
		if prev == cur:
			cnt += 1
		else:
			ct.append(cnt)
			cnt = 1
		if i == n - 1:
			ct.append(cnt)
	l = len(ct)
	s = len(set(ct))
	if s != l:
		ans = 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	d = {}
	flag = 0
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = [i, 1]
		elif a[i] in d and d[a[i]][0] + 1 == i:
			temp = d[a[i]][1]
			d[a[i]] = [i, temp + 1]
		else:
			print('NO')
			flag = 1
			break
	vals = list(d.values())
	dist = []
	for i in vals:
		dist.append(i[1])
	if flag == 0:
		if len(dist) == len(set(dist)):
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	input()
	b = list(map(int, input().split()))
	c = {b[0]: 1}
	r = b[0]
	f = 1
	for x in range(1, len(b)):
		if r == b[x]:
			c[b[x]] += 1
			r = b[x]
		elif b[x] in c:
			print('NO')
			f = 0
			break
		else:
			c[b[x]] = 1
			r = b[x]
	if f:
		if len(list(c.values())) == len(set(c.values())):
			print('YES')
		else:
			print('NO')


from collections import defaultdict
get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
for _ in range(get_int()):
	N = get_int()
	A = get_mint()
	D = defaultdict(list)
	for i in range(N):
		D[A[i]].append(i)
		if len(D[A[i]]) > 1 and D[A[i]][-1] - D[A[i]][-2] > 1:
			print('NO')
			break
	else:
		C = defaultdict(int)
		for v in D.values():
			C[len(v)] += 1
			if C[len(v)] > 1:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
for i in range(t):
	wrong = 0
	n = int(input())
	recipelist = [int(a) for a in input().split()]
	dict = {}
	for j in recipelist:
		if j in dict.keys():
			dict[j] = dict[j] + 1
		else:
			dict[j] = 1
	countlist = list()
	for h in dict.values():
		countlist.append(h)
	unique = list(set(countlist))
	if len(unique) < len(countlist):
		wrong = 1
	elif len(unique) == len(countlist):
		new = list()
		new.append(recipelist[0])
		for u in range(1, len(recipelist)):
			if recipelist[u] != recipelist[u - 1]:
				if recipelist[u] in new:
					wrong = 1
					break
				else:
					new.append(recipelist[u])
	if wrong == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	j = 0
	f = []
	while j < n:
		c = 1
		r = 0
		for k in range(j + 1, n):
			if a[k] == a[j]:
				if r == 0:
					c += 1
				else:
					print('NO')
					r = 2
					break
			else:
				r = 1
		if r == 2:
			break
		for h in f:
			if c == h:
				print('NO')
				r = 2
				break
		f.append(c)
		if r == 2:
			break
		j += c
	if r != 2:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	d = {}
	a = []
	flag = 1
	arr = list((int(i) for i in input().split()))
	r = arr[0]
	d[r] = 1
	for i in arr[1:]:
		if i == r:
			d[r] += 1
		elif i in d:
			print('NO')
			flag = 0
			break
		else:
			d[i] = 1
			r = i
	if flag == 1:
		if len(list(d.values())) == len(set(d.values())):
			print('YES')
		else:
			print('NO')


for __ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	s = set()
	flag = 0
	for i in range(n):
		if arr[i] in list(d.keys()):
			d[arr[i]] += 1
		else:
			d[arr[i]] = 1
		curr_ele = arr[i]
		if curr_ele in s and arr[i - 1] != arr[i]:
			flag = 1
			break
		else:
			s.add(arr[i])
	c = list(d.values())
	if len(c) != len(set(c)):
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


def check(l):
	c = []
	s = list(set(l))
	for i in s:
		c.append(l.count(i))
	if len(c) == len(set(c)):
		return 1
	return 0
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	if check(l) == 0:
		print('NO')
		continue
	for i in range(1, n):
		if l[i] != l[i - 1]:
			s += 1
	if s == len(set(l)) - 1:
		print('YES')
	else:
		print('NO')


from collections import Counter

def solve(arr):
	n = len(arr)
	d = Counter(arr)
	if len(d.values()) != len(set(d.values())):
		return False
	i = 0
	j = 0
	while i < n and j < n:
		j = i + 1
		while j < n and arr[j] == arr[i]:
			j = j + 1
		if j - i != d[arr[i]]:
			return False
		i = j
	return True
for _ in range(int(input())):
	n = int(input())
	arr = [int(num) for num in input().split(' ')]
	ans = solve(arr)
	if ans == True:
		print('YES')
	else:
		print('NO')


def fun():
	n = int(input())
	a = list(map(int, input().split()))
	mark = {}
	s = {}
	for i in range(n):
		if a[i] in mark:
			if a[i] == a[i - 1]:
				mark[a[i]] += 1
			else:
				return 'NO'
		else:
			mark[a[i]] = 1
	count = set(mark.values())
	if len(count) == len(mark):
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	print(fun())


n = int(input())
for i in range(n):
	N = int(input())
	x = list(map(int, input().split()))
	alpha = {}
	beta = []
	flag = 0
	for i in range(len(x)):
		if x[i] not in beta:
			if x[i] in alpha:
				alpha[x[i]] += 1
			else:
				alpha.setdefault(x[i], 1)
			if i != len(x) - 1:
				if x[i + 1] != x[i]:
					beta.append(x[i])
		else:
			flag = 1
			break
	b = list(alpha.values())
	b.sort()
	c = list(set(b))
	c.sort()
	if c != b:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	freq = {}
	freq[arr[0]] = 1
	flag = 0
	for i in range(1, n):
		if arr[i - 1] != arr[i] and arr[i] in freq:
			flag = 1
			break
		if arr[i] in freq:
			freq[arr[i]] += 1
		else:
			freq[arr[i]] = 1
	sam = []
	for i in freq:
		sam.append(freq[i])
	sam2 = list(set(sam))
	sam.sort()
	sam2.sort()
	if sam != sam2:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = input().split(' ')
	for j in range(n):
		l[j] = int(l[j])
	f = 0
	for j in range(n):
		for k in range(j + 1, n):
			if l[k] == l[j] and l[k - 1] != l[j]:
				f = 1
				break
		if f == 1:
			break
	if f == 1:
		print('NO')
	else:
		f = 0
		u = list(set(l))
		for j in range(len(u)):
			for k in range(j + 1, len(u)):
				if l.count(u[j]) == l.count(u[k]):
					f = 1
					break
			if f == 1:
				break
		if f == 1:
			print('NO')
		else:
			print('YES')


def fun(l):
	t = []
	s = list(set(l))
	for i in s:
		t.append(l.count(i))
	if len(t) == len(set(t)):
		return 1
	return 0
for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	s = 0
	if fun(l) == 0:
		print('NO')
	else:
		for i in range(n - 1):
			if l[i] != l[i + 1]:
				s += 1
		if s == len(set(l)) - 1:
			print('YES')
		else:
			print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	lis = [arr[0]]
	lis += [arr[i] for i in range(1, n) if arr[i - 1] != arr[i]]
	if len(set(lis)) != len(lis):
		print('NO')
	else:
		c = dict(Counter(arr))
		if len(set(c.values())) == len(c):
			print('YES')
		else:
			print('NO')