Polycarp has $26$ tasks. Each task is designated by a capital letter of the Latin alphabet.

The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.

Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.

For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".

If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".

Help Polycarp find out if his teacher might be suspicious.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 1000$). Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 50$) — the number of days during which Polycarp solved tasks.

The second line contains a string of length $n$, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.


-----Output-----

For each test case output:

"YES", if the teacher cannot be suspicious;

"NO", otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).


-----Examples-----

Input
5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB
Output
NO
NO
YES
YES
YES


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Implementation

Complete search


Solutions:
import sys
for _ in range(int(input())):
	n = int(input())
	strs = list(input())
	alpha = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
	used = []
	flag = True
	for i in range(len(strs) - 1):
		if strs[i + 1] == strs[i]:
			pass
		elif strs[i + 1] in used:
			flag = False
			break
		else:
			used.append(strs[i])
	if flag:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline().strip()
	check = ''
	flag = True
	for i in range(n - 1):
		if s[i] in check or s[i + 1] in check:
			flag = False
			break
		if s[i] != s[i + 1]:
			check += s[i]
	if flag == False:
		print('NO')
	else:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	s = input()
	x = Counter(s)
	string = ''
	for m in x:
		string += m * x[m]
	if string == s:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	if n == 1:
		print('YES')
	else:
		f = 0
		for i in s:
			if i in l and l[len(l) - 1] != i:
				print('NO')
				f = 1
				break
			else:
				l.append(i)
		if f == 0:
			print('YES')


def teacher(s):
	seen = set([s[0]])
	for i in range(1, len(s)):
		if s[i] in seen and s[i] != s[i - 1]:
			return False
		seen.add(s[i])
	return True
for _ in range(int(input())):
	n = int(input())
	s = input()
	print('YES' if teacher(s) else 'NO')


def main():
	t = int(input())
	for _ in range(1, t + 1):
		n = int(input())
		s = input()
		unique = set()
		temp = ''
		not_suspicious = True
		for c in s:
			if c == temp:
				pass
			elif ord(c) in unique:
				not_suspicious = False
				break
			else:
				temp = c
				unique.add(ord(c))
		if not_suspicious:
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for i in range(t):
	n = int(input())
	res = 'YES'
	s = input()
	for j in range(1, n):
		if s[j] in s[:j] and s[j] != s[j - 1]:
			res = 'NO'
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	for i in range(1, len(s)):
		if s[i] in s[:i] and s[i] != s[i - 1]:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	l = list(s)
	nb = len(set(l))
	nn = 0
	for j in range(n - 1):
		if s[j] != s[j + 1]:
			nn += 1
	if n == 1:
		print('YES')
	elif nb > nn:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	n = int(input())
	task = input()
	num = [0 for i in range(30)]
	task = list(task)
	l = len(task)
	ok = True
	for i in range(0, l):
		u = ord(task[i]) - ord('A')
		if i and task[i] != task[i - 1] and num[u]:
			ok = False
		num[u] = 1
	print('YES' if ok else 'NO')
	T -= 1


def fun(n, s):
	l = []
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			continue
		elif s[i] not in l and s[i + 1] not in l:
			l.append(s[i])
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(fun(n, s))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def suspicious(n, s):
	seen = set()
	seen.add(s[0])
	for i in range(1, n):
		if s[i] != s[i - 1] and s[i] in seen:
			print('NO')
			return
		seen.add(s[i])
	print('YES')
	return
t = inp()
for i in range(t):
	n = inp()
	s = insr()
	suspicious(n, s)


t = int(input())
while t:
	n = int(input())
	a = input()
	li = []
	for i in range(26):
		li.append(0)
	for i in range(n):
		li[ord(a[i]) - ord('A')] += 1
	i = 0
	flag = 1
	while i < n:
		for j in range(li[ord(a[i]) - ord('A')]):
			if a[i + j] != a[i]:
				flag = 0
				break
		i += li[ord(a[i]) - ord('A')]
		if flag == 0:
			break
	if flag:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	for i in s:
		if i not in l:
			l.append(i)
		if l[-1] == i:
			pass
		else:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print('Yes')
		continue
	l = [s[0]]
	ans = 'Yes'
	for i in s[1:]:
		if i in l and i != l[-1]:
			ans = 'No'
			break
		l.append(i)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	temp = s[0]
	for i in range(1, len(s)):
		if s[i - 1] != s[i]:
			temp += s[i]
	arr = [0] * 256
	for i in range(len(temp)):
		arr[ord(temp[i])] += 1
		if arr[ord(temp[i])] > 1:
			print('NO')
			break
	else:
		print('YES')


import sys
input = sys.stdin.readline

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

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

def mps(A):
	return [tuple(map(int, input().split())) for _ in range(A)]
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque

def ceil(U, V):
	return (U + V - 1) // V

def modf1(N, MOD):
	return (N - 1) % MOD + 1
inf = int(1e+20)
mod = int(1000000000.0 + 7)

def rle(lst):
	ans = []
	cnt = 1
	ini = lst[0]
	for i in range(1, len(lst)):
		if ini == lst[i]:
			cnt += 1
		else:
			ans.append((ini, cnt))
			cnt = 1
			ini = lst[i]
	ans.append((ini, cnt))
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input()[:-1])
	s = rle(s)
	used = [0] * 26
	f = True
	for (i, j) in s:
		if used[ord(i) - ord('A')] == 0:
			used[ord(i) - ord('A')] += 1
		else:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	s = input()
	d = defaultdict(lambda : [])
	f = 1
	for i in range(n):
		if d[s[i]]:
			if abs(i - d[s[i]][-1]) != 1:
				f = 0
				break
		d[s[i]].append(i)
	if f:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	n = int(input())
	s = input()
	d = dict()
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	i = 0
	c = 0
	flag = 0
	while i < n:
		c = 1
		j = i + 1
		while j < n and s[i] == s[j]:
			j += 1
			c += 1
		if d[s[i]] != c:
			flag = 1
			break
		i = j
	if flag == 1:
		print('NO')
	else:
		print('YES')
	T -= 1


t = int(input())
for _ in range(t):
	m = []
	n = int(input())
	s = input()
	fl = True
	m.append(s[0])
	for i in range(1, len(s)):
		if s[i] != s[i - 1] and s[i] in m:
			fl = False
			break
		m.append(s[i])
	if fl:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(n):
	t = int(input())
	s = input()
	if s[-1] == 'a':
		s += 'b'
	else:
		s += 'a'
	l = []
	t = True
	for i in range(1, len(s)):
		if s[i] in l:
			t = False
		elif s[i] != s[i - 1]:
			l.append(s[i - 1])
	if t:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	ans = 0
	a = int(input())
	st = list(str(input()))
	l = [st[0]]
	for j in range(a):
		if l[-1] == st[j] or st[j] not in l:
			l.append(st[j])
			ans += 0
		else:
			ans += 1
	print('YES') if ans == 0 else print('NO')


for t in range(int(input())):
	n = int(input())
	s = input()
	db = set()
	flag = 0
	for x in range(len(s)):
		if s[x] not in db:
			db.add(s[x])
		elif s[x] == s[x - 1]:
			continue
		else:
			print('NO')
			flag = 1
			break
	if flag == 0:
		print('YES')


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	tmp = []
	ans = 0
	if n == 1:
		print('YES')
		continue
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			continue
		else:
			tmp.append(s[i])
			if s[i + 1] in tmp:
				ans = 1
				break
	if ans == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	tasks = input()
	check = set(tasks[0])
	last = tasks[0]
	suspicious = False
	for i in range(1, n):
		if tasks[i] != last and tasks[i] in check:
			suspicious = True
			break
		check.add(tasks[i])
		last = tasks[i]
	if suspicious:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input()
	s = [a[0]]
	for i in range(1, n):
		if s[-1] != a[i]:
			s.append(a[i])
	if sorted(list(set(a))) == sorted(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	tasks = input()
	j = 0
	while j < n - 1:
		if tasks[j] == tasks[j + 1]:
			pass
		elif tasks[j] in tasks[j + 1:n]:
			print('NO')
			break
		j += 1
	if j == n - 1:
		print('YES')


cases = int(input())
for i in range(cases):
	days = int(input())
	tasks = input()
	solved_tasks = []
	suspicious = True
	for j in range(days - 1):
		if tasks[j] in solved_tasks:
			suspicious = False
			break
		if tasks[j] != tasks[j + 1]:
			solved_tasks.append(tasks[j])
	if tasks[-1] in solved_tasks:
		suspicious = False
	if suspicious == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	s = list(s)
	for j in range(len(s)):
		temp = j
		c = 0
		b = 0
		for k in range(j + 1, len(s)):
			if s[j] == s[k]:
				if k - temp == 1:
					temp = k
				else:
					c = 1
			if c == 1:
				print('NO')
				b = 1
				break
		if b == 1:
			break
	else:
		print('YES')


def problems_checker(problems):
	clear_data = []
	for i in problems:
		if clear_data == [] or i != clear_data[-1]:
			clear_data.append(i)
	if len(clear_data) == len(set(clear_data)):
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	n = int(input())
	p = input()
	problems_checker(p)


t = int(input())
for i in range(0, t):
	n = int(input())
	str_ = input()
	str_list = []
	str_list.append(str_[0])
	flag = 0
	for j in range(0, n):
		if str_[j] == str_list[-1]:
			flag = 1
		elif str_list.count(str_[j]) == 1:
			flag = 0
			break
		else:
			str_list.append(str_[j])
			flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


def do_not_be_distracted(str):
	lista_n_repetidas = []
	for c in str:
		if c not in lista_n_repetidas:
			lista_n_repetidas.append(c)
	verificadas = []
	for i in range(len(lista_n_repetidas)):
		for j in range(len(str) - 1):
			if str[j] not in verificadas:
				if str[j] != str[j + 1]:
					verificadas.append(str[j])
					c = j
					f = len(str) - 1
					for k in range(c, len(str) - 1):
						if str[c] == str[f]:
							return 'NO'
						else:
							f -= 1
	return 'YES'
n = int(input())
for l in range(n):
	d = int(input())
	str = input()
	print(do_not_be_distracted(str))


for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = 1
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			t = s.rfind(s[i])
			if t != i:
				flag = 0
				break
	if flag:
		print('YES')
	else:
		print('NO')


import math
from math import floor, sqrt, log
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
mod = 1000000007

def gcd(num1: int, num2: int):
	if num1 == 0:
		return num2
	if num2 == 0:
		return num1
	if num1 > num2:
		return gcd(num1 % num2, num2)
	else:
		return gcd(num1, num2 % num1)

def lcm(num1: int, num2: int):
	return num1 * num2 // gcd(num1, num2)
a = inp()

def func(n, m):
	b = []
	flag = 0
	for i in range(n):
		if m[i] in b and m[i] != m[i - 1]:
			flag = 1
		else:
			b.append(m[i])
	if flag == 1:
		print('NO')
	else:
		print('YES')
	pass
for i in range(a):
	n = inp()
	m = strl()
	func(n, m)


t = int(input())
for x in range(t):
	l = int(input())
	n = input()
	for i in range(1, len(n)):
		if n[i] in n[:i] and n[i] != n[i - 1]:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	s = input()
	li = []
	f = 0
	for i in range(1, n):
		if s[i - 1] != s[i]:
			li.append(s[i - 1])
			if s[i] in li:
				f = 1
				break
	if f == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	c = input()
	l = []
	k = 1
	for i in range(len(c)):
		if c[i] == c[i - 1] or c[i] not in l:
			l.append(c[i])
		else:
			k = 0
			break
	if k == 0:
		print('NO')
	else:
		print('YES')


def check(str, length):
	memo = {}
	for i in range(length):
		if str[i] in memo.keys():
			if memo[str[i]] + 1 != i:
				return 'NO'
		memo[str[i]] = i
	return 'YES'
for i in range(int(input())):
	n = int(input())
	tasks = input()
	print(check(tasks, n))


def yesno(ans):
	if ans:
		print('YES')
	else:
		print('NO')

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		d = {}
		ans = 1
		d[s[0]] = 1
		for i in range(1, n):
			if s[i] == s[i - 1]:
				continue
			elif d.get(s[i]):
				ans = 0
				break
			else:
				d[s[i]] = d.get(s[i], 0) + 1
		yesno(ans)
main()


def passed(x, n):
	exists = []
	i = 0
	while i < n:
		if x[i] in exists:
			return 'NO'
		exists.append(x[i])
		i += 1
		while i < n and x[i] == x[i - 1]:
			i += 1
	return 'YES'
for q in range(int(input())):
	n = int(input())
	x = input()
	print(passed(x, n))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	check = set()
	flag = 0
	for i in range(0, len(s) - 1):
		if s[i] != s[i + 1]:
			if s[i + 1] in check:
				flag = 1
				break
			else:
				check.add(s[i])
		else:
			check.add(s[i])
	if flag == 1:
		print('NO')
	else:
		print('YES')


def solve(n, s):
	d = {}
	seen = s[0]
	d[s[0]] = 1
	for i in range(1, n):
		current = s[i]
		if current == seen:
			d[current] += 1
			seen = current
		elif current in d.keys():
			if d[current] > 0:
				return 'NO'
		else:
			d[current] = 1
			seen = current
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	print(solve(n, s))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ls = [0] * 26
	ele = s[0]
	flag = 0
	for i in range(1, len(s)):
		if ele == s[i]:
			continue
		elif ls[ord(s[i]) - 65] == 0:
			ele = s[i]
			ls[ord(s[i - 1]) - 65] = 1
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	l = []
	p = 0
	for i in range(0, n):
		if s[i] not in l:
			l.append(s[i])
		elif s[i - 1] != s[i]:
			p = 1
			break
	if p == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = [False] * 26
	f = 0
	i = 0
	while i < n:
		if b[ord(a[i]) - ord('A')]:
			f = 1
			break
		else:
			b[ord(a[i]) - ord('A')] = True
			while i < n - 1 and a[i] == a[i + 1]:
				i += 1
			i += 1
	if f == 1:
		print('NO')
	else:
		print('YES')


def check(st):
	lt = []
	k = 0
	for i in range(len(st)):
		if st[i] not in lt:
			lt.append(st[i])
		elif st[i] in lt and st[i] != st[i - 1]:
			return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	n = int(input())
	st = input()
	print(check(st))


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = 0
	for i in range(n):
		for j in range(i + 1, n):
			if s[j - 1] != s[i] and s[j] == s[i]:
				f = 1
				break
		if f == 1:
			break
	if f == 0:
		print('yes')
	if f == 1:
		print('no')


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	a = [0] * 26
	for (j, i) in enumerate(s):
		if a[ord(i) - 65] and s[j - 1] != s[j]:
			print('NO')
			break
		a[ord(i) - 65] = 1
	else:
		print('YES')


n = int(input())

def func(_list, val):
	for k in range(length - 1, -1, -1):
		if val == _list[k]:
			return k
	return 0
for i in range(n):
	length = int(input())
	string = input()
	str_list = [*string]
	flag = 0
	for j in range(length - 1):
		a = func(str_list, str_list[j])
		if str_list[j] != str_list[j + 1] and a - j > 1:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = []
	flag = 0
	i = 0
	while i < n:
		if s[i] not in l:
			l.append(s[i])
		elif s[i - 1] != s[i]:
			flag = 1
		if flag == 1:
			break
		i += 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
while n > 0:
	f = int(input())
	s = input()
	c = 0
	for i in range(f - 1):
		if s[i] == s[i + 1]:
			continue
		for j in range(i + 1, f):
			if s[i] == s[j]:
				c += 1
				break
		if c > 0:
			break
	if c > 0:
		print('NO')
	else:
		print('YES')
	n -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	vis = [0 for _ in range(26)]
	k = len(s)
	i = 0
	flag = False
	while i < k:
		c = s[i]
		if vis[ord('A') - ord(c)] != 0:
			flag = True
			break
		while i < k and s[i] == c:
			i += 1
		vis[ord('A') - ord(c)] = -1
	if flag:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	s = 'YES'
	l = list(map(str, input()))
	d = []
	for i in range(n - 1):
		if l[i] != l[i + 1]:
			d.append(l[i])
		if l[i + 1] in d:
			s = 'NO'
			break
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = sorted(s)
	(res, res_n) = (0, 0)
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			res += 1
		if k[i] != k[i + 1]:
			res_n += 1
	if res == res_n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	d = set()
	s = input()
	d.add(s[0])
	b = True
	for i in range(1, n):
		if s[i] in d and s[i] != s[i - 1]:
			b = False
			break
		else:
			d.add(s[i])
	if b:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	input()
	char = list(input())
	unique = []
	con = ''
	while char:
		c = char.pop()
		if not con:
			con = c
			unique.append(c)
		if c != con:
			unique.append(c)
		con = c
	if len(unique) != len(set(unique)):
		print('NO')
	else:
		print('YES')


for _ in range(0, int(input())):
	n = int(input())
	s = input()
	arr = []
	arr.append(s[0])
	for i in range(0, n):
		if arr[-1] != s[i]:
			arr.append(s[i])
	l = len(arr)
	cl = len(set(arr))
	if l == cl:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = int(input())
	b = input()
	c = ''
	g = 0
	for i in range(len(b)):
		if b[i] not in c:
			c += b[i]
		elif b[i] != c[-1] and b[i] in c:
			g = 1
			break
		else:
			c += b[i]
	if g == 0:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	s = input()
	n = len(s)
	d = dict()
	d[s[0]] = 1
	flag = True
	for i in range(1, n):
		if s[i] == s[i - 1]:
			d[s[i]] += 1
		elif s[i] != s[i - 1] and s[i] not in d:
			d[s[i]] = 1
		else:
			print('No')
			flag = False
			break
	if flag:
		print('Yes')


def binary_search(arr, x):
	left = 0
	right = len(arr) - 1
	mid = 0
	while left <= right:
		mid = (left + right) // 2
		if x == arr[mid]:
			return True
		if arr[mid] < x:
			left = mid + 1
		else:
			right = mid - 1
	return False

def f(s, n):
	if n == 1:
		print('YES')
	else:
		l = list(s)
		var = 0
		for i in range(n - 1):
			if l[i] != l[i + 1]:
				if binary_search(sorted(l[i + 1:]), l[i]):
					print('NO')
					var = 1
					break
		if var == 0:
			print('YES')
t = int(input())
i = 0
while i != t:
	i = i + 1
	n = int(input())
	s = input()
	f(s, n)


for _ in range(int(input())):
	input()
	k = input()
	c = 0
	for i in range(len(k) - 1):
		if k[i] != k[i + 1]:
			c += 1
	if c == len(set(k)) - 1:
		print('YES')
	else:
		print('NO')


import os
import collections
import itertools
import math
import bisect
from math import floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007

def gcd(num1: int, num2: int):
	if num1 == 0:
		return num2
	if num2 == 0:
		return num1
	if num1 > num2:
		return gcd(num1 % num2, num2)
	else:
		return gcd(num1, num2 % num1)

def lcm(num1: int, num2: int):
	return num1 * num2 // gcd(num1, num2)

def big_power(num1: int, num2: int):
	result = 1
	while num2 > 0:
		if num2 & 1:
			result = result * num1
		num1 = num1 ** 2
		num2 >>= 1
	return result

def sieve_of_eratosthenes(number: int):
	num1 = (number - 1) // 2
	arr = [True] * num1
	(num2, num3, primes) = (0, 3, [2])
	while num3 * num3 < number:
		if arr[num2]:
			primes.append(num3)
			num4 = 2 * num2 * num2 + 6 * num2 + 3
			while num4 < num1:
				arr[num4] = False
				num4 = num4 + 2 * num2 + 3
		num2 += 1
		num3 += 1
	while num2 < num1:
		if arr[num2]:
			primes.append(num3)
		num2 += 1
		num3 += 2
	return primes

def dfs(graph, start, visited=None):
	if visited is None:
		visited = set()
	visited.add(start)
	for next in graph[start] - visited:
		dfs(graph, next, visited)
	return visited

def dfs_paths(graph, start, goal):
	stack = [(start, [start])]
	while stack:
		(vertex, path) = stack.pop()
		for next in graph[vertex] - set(path):
			if next == goal:
				yield (path + [next])
			else:
				stack.append((next, path + [next]))
	return stack

def bfs(graph, start):
	(visited, queue) = (set(), [start])
	while queue:
		vertex = queue.pop(0)
		if vertex not in visited:
			visited.add(vertex)
			queue.extend(graph[vertex] - visited)
	return visited

def bfs_paths(graph, start, goal):
	queue = [(start, [start])]
	while queue:
		(vertex, path) = queue.pop(0)
		for next in graph[vertex] - set(path):
			if next == goal:
				yield (path + [next])
			else:
				queue.append((next, path + [next]))
	return queue
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
a = inp()

def func(n, m):
	b = []
	flag = 0
	for i in range(n):
		if m[i] in b and m[i] != m[i - 1]:
			flag = 1
		else:
			b.append(m[i])
	if flag == 1:
		print('NO')
	else:
		print('YES')
	pass
for i in range(a):
	n = inp()
	m = strl()
	func(n, m)


test_cases = int(input())
for i in range(test_cases):
	num_letters = int(input())
	letters_list = input()
	cur_letter = letters_list[0]
	finished_tasks = []
	suspicious = False
	for letter in letters_list:
		if letter in finished_tasks:
			suspicious = True
			break
		if letter == cur_letter:
			continue
		else:
			finished_tasks.append(cur_letter)
			cur_letter = letter
	if not suspicious:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	j = 1
	l1 = []
	for i in range(1, len(s)):
		if s[i - 1] != s[i]:
			if s[i] in l1:
				j = 0
				break
			else:
				l1.append(s[i - 1])
	if j == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	c = 0
	n = int(input())
	s = input()
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			for j in range(i + 1, n):
				if s[i] == s[j]:
					c = 1
					break
	if c == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
from math import sqrt, floor, ceil
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	found = {arr[0]: 1}
	g = 0
	for i in range(1, n):
		if arr[i] in found and arr[i - 1] != arr[i]:
			g = 1
			break
		else:
			found[arr[i]] = 1
	print('NO' if g == 1 else 'YES')


from math import gcd, floor, sqrt, log
mod = 1000000007
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
il = lambda : list(map(int, input().strip().split()))
fl = lambda : list(map(float, input().strip().split()))
seq = lambda : list(map(int, input().strip().split()))

def main():
	n = inp()
	s = strng()
	l = list()
	vis = set()
	i = 0
	if n == 1:
		print('YES')
		return
	while i < n:
		if s[i] not in vis:
			vis.add(s[i])
			last = s[i]
			i += 1
		elif s[i] == last:
			i += 1
			continue
		else:
			print('NO')
			return
	print('YES')
for t in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = True
	arr = [0]
	for i in s:
		if i == arr[-1]:
			pass
		elif i in arr[:-1]:
			print('NO')
			flag = False
			break
		else:
			arr.append(i)
	if flag:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	d = dict()
	d[s[0]] = True
	ans = True
	for j in range(1, n):
		if s[j] != s[j - 1] and d.get(s[j]) == None:
			d[s[j]] = True
		elif s[j] != s[j - 1]:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	st = set()
	f = 0
	st.add(s[0])
	for j in range(1, len(s)):
		if s[j] != s[j - 1]:
			l = len(st)
			st.add(s[j])
			if l == len(st):
				f = 1
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


def fnc(s):
	chars = list(s)
	prev = None
	k = 0
	for c in s:
		if prev != c:
			chars[k] = c
			prev = c
			k = k + 1
	return ''.join(chars[:k])

def func(s):
	l = []
	s = fnc(s)
	for i in range(len(s)):
		if s[i] not in l:
			l.append(s[i])
		elif s[i] in l:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	n = int(input())
	s = input()
	func(s)


t1 = int(input())
for i in range(t1):
	n = int(input())
	b = ''
	c = 0
	s = list(input())
	a = []
	for i in s:
		if b != i:
			l = i in a
			if l == False:
				a.append(i)
				b = i
			else:
				print('NO')
				c = 1
				break
	if c == 0:
		print('YES')


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	n = ini()
	s = ins()
	count = dict()
	last = ''
	ans = True
	for i in s:
		if i not in count:
			count[i] = 0
		elif last != i:
			ans = False
			break
		count[i] += 1
		last = i
	print('YES' if ans else 'NO')


def inp():
	A = [int(x) for x in input().split()]
	return A
T = int(input())
while T > 0:
	T -= 1
	N = int(input())
	S = input()
	d = {}
	p = S[0]
	j = 1
	d[p] = 1
	flg = True
	while j < N:
		if p != S[j]:
			if S[j] in d:
				flg = False
				break
		p = S[j]
		d[p] = 1
		j += 1
	if flg:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	lst = []
	flag = 1
	lst.append(s[0])
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			continue
		else:
			lst.append(s[i])
	while lst:
		if lst.pop(0) in lst:
			print('NO')
			flag = 0
			break
	if flag == 0:
		continue
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = input()
	(last_char, past_char) = (None, set())
	flag = True
	for i in range(n):
		curr = arr[i]
		if curr == last_char:
			past_char.add(curr)
		elif curr not in past_char:
			past_char.add(last_char)
			last_char = curr
		else:
			flag = False
			break
	if flag is True:
		print('YES')
	else:
		print('NO')


T = int(input())

def solve():
	n = int(input())
	string = input()
	res = [string[0]]
	curr_elem = string[0]
	for i in range(1, n):
		if string[i] != curr_elem:
			if string[i] in res:
				print('NO')
				return
			else:
				res.append(string[i])
				curr_elem = string[i]
	print('YES')
	return
for i in range(T):
	solve()


t = int(input())
while t > 0:
	t -= 1
	b = False
	n = int(input())
	m = input()
	set1 = set({})
	set1.add(m[0])
	for i in range(1, len(m)):
		if m[i - 1] != m[i]:
			l = len(set1)
			set1.add(m[i])
			if len(set1) == l:
				b = True
				break
	if b:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	p = input()
	c = p
	y = 0
	f = True
	d = 'YES'
	z = list(set(p))
	for i in range(len(z)):
		while True:
			x = p.find(z[i])
			if x != -1:
				p = p[0:x] + ' ' + p[x + 1:]
				if x - y == 1 or f:
					f = False
					y = x
					continue
				else:
					d = 'NO'
					break
			else:
				break
		if d == 'NO':
			print(d)
			break
		p = c
		f = True
		y = 0
	if d == 'YES':
		print(d)


it = int(input())

def fun(le, arr, m, flag):
	for i in range(len(m) - 1):
		if m[i] == m[i + 1] and arr[le - 1] != m[i]:
			arr.append(m[i])
			le = len(arr)
		elif arr[le - 1] != m[i + 1]:
			arr.append(m[i + 1])
			le = len(arr)
	for i in range(1, len(arr)):
		if arr.count(arr[i]) >= 2:
			flag = 0
	if flag == 1:
		print('YES')
	else:
		print('NO')
for i in range(it):
	non = int(input())
	m = list(input())
	arr = [0]
	arr.append(m[0])
	le = len(arr)
	flag = 1
	fun(le, arr, m, flag)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	alphabet_fixe = s[0]
	l = [s[0]]
	for j in range(1, n):
		if s[j] != alphabet_fixe:
			alphabet_fixe = s[j]
			l.append(s[j])
	if len(set(l)) == len(l):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	l = [0 for i in range(26)]
	n = int(input())
	s = input()
	l[ord(s[0]) - 65] = 1
	for i in range(1, n):
		if s[i] != s[i - 1] and l[ord(s[i]) - 65]:
			print('NO')
			break
		elif s[i] != s[i - 1]:
			l[ord(s[i]) - 65] = 1
	else:
		print('YES')


rodadas = int(input())
for a in range(rodadas):
	numeroDias = int(input())
	dias = input()
	contador = 0
	for b in range(numeroDias):
		for c in range(b + 1, numeroDias, 1):
			if dias[b] == dias[c] and dias[c - 1] != dias[c]:
				print('NO')
				contador = 1
				break
		if contador == 1:
			break
		if b == numeroDias - 1 and contador == 0:
			print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	d = {}
	ans = 'YES'
	for i in range(len(s)):
		if d.get(s[i]) == None:
			d[s[i]] = 1
		elif s[i - 1] == s[i]:
			continue
		else:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = list(s)
	c = 0
	for i in range(1, n):
		if l[i] == l[i - 1]:
			i = i + 1
		else:
			for j in range(i, n):
				if l[i - 1] == l[j]:
					c = 1
				else:
					j = j + 1
	if c == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	lst = [x for x in s]
	se = set(lst)
	l = []
	for i in se:
		a = lst.count(i)
		if i * a not in s:
			print('NO')
			break
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	k = []
	i = 0
	for j in input():
		if j in k and k[len(k) - 1] != j:
			print('NO')
			break
		elif j in k:
			i = i + 1
			continue
		else:
			k.append(j)
		i = i + 1
	if i == n:
		print('YES')


for case in range(int(input())):
	n = int(input())
	tasks = input()
	notSuspicious = 'YES'
	for i in range(1, n):
		if tasks[i] in tasks[:i] and tasks[i] != tasks[i - 1]:
			notSuspicious = 'NO'
			break
	print(notSuspicious)


def get_problem_status(tasks):
	st = set()
	codes = list(map(ord, tasks))
	n = len(tasks)
	for i in range(n - 1):
		curr = codes[i]
		ne = codes[i + 1]
		if curr - ne != 0:
			st.add(curr)
			if ne in st:
				return 'NO'
	return 'YES'
tests = int(input())
for i in range(tests):
	n = int(input())
	tasks = input()
	if n == 1:
		print('YES')
	else:
		print(get_problem_status(tasks))


n = int(input())
counter = 0
length = []
ele = []
while counter < n:
	length.append(int(input()))
	ele.append(input())
	counter += 1
for i in ele:
	temp = []
	nochar = 0
	counter2 = 0
	for j in range(len(i)):
		if i[j] not in temp:
			temp.append(i[j])
			nochar += 1
		else:
			if j == 0:
				continue
			if i[j] == i[j - 1]:
				counter2 += 1
	if counter2 + nochar == len(i):
		print('YES')
	else:
		print('NO')


n = int(input())
li = []

def check(s):
	l = []
	for j in range(len(s)):
		if s[j] in l and l[-1] != s[j]:
			return 'No'
		l.append(s[j])
	return 'Yes'
for i in range(n):
	k = int(input())
	s = input()
	print(check(s))


import itertools
for i in range(int(input())):
	a = int(input())
	s = [i for i in input()]
	lst = [(k, sum((1 for _ in vs))) for (k, vs) in itertools.groupby(s)]
	flag = 0
	for i in range(len(lst)):
		for j in range(i + 1, len(lst)):
			if lst[i][0] == lst[j][0]:
				flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


def solve(task):
	unique = set(task)
	segments = 0
	prev = ' '
	for letter in task:
		if letter != prev:
			segments += 1
		prev = letter
	return 'YES' if len(unique) == segments else 'NO'
T = int(input().strip())
for _ in range(T):
	days = int(input().strip())
	tasks = input().strip()
	print(solve(tasks))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = set()
	i = 0
	flag = 0
	while i < n:
		if s[i] in x:
			flag = 1
			break
		j = i + 1
		while j < n and s[j] == s[i]:
			j += 1
		x.add(s[i])
		i = j
	if flag == 0:
		print('Yes')
	else:
		print('No')


def transforma_em_lista(lista):
	minha = []
	for c in lista:
		minha.append(c)
	return minha

def remove_excesso(valores):
	indices = []
	for v in range(len(valores) - 1):
		if valores[v] == valores[v + 1]:
			indices.append(v + 1)
	for p in range(len(indices) - 1, -1, -1):
		valores.pop(indices[p])
	return valores

def compara(lista):
	for valor in lista:
		compara = lista.count(valor)
		if compara > 1:
			return 'NO'
	return 'YES'
n = int(input())
for c in range(n):
	days = int(input())
	str = transforma_em_lista(input())
	lista_pronta = remove_excesso(str)
	print(compara(lista_pronta))


for i in range(int(input())):
	n = int(input())
	ls = list(map(str, input()))
	lss = set(ls)
	j = None
	lj = j
	no = False
	for j in ls:
		if j != lj:
			if not j in lss:
				print('NO')
				no = True
				break
			else:
				lss.remove(j)
		lj = j
	if not no:
		print('YES')


test_cases = int(input())
for t in range(test_cases):
	n = int(input())
	task_order = input()
	seen = []
	flag = True
	i = 0
	while i < len(task_order):
		letter = task_order[i]
		if letter not in seen:
			seen.append(letter)
		else:
			flag = False
			break
		while True:
			i += 1
			if i == len(task_order) or letter != task_order[i]:
				break
	if flag:
		print('YES')
	else:
		print('NO')


for h in [*open(0)][2::2]:
	f = 1
	z = list(set(h))
	for s in z:
		x = h.index(s)
		y = len(h) - h[::-1].index(s)
		if y - x == h.count(s):
			continue
		else:
			f = 0
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		tasks = input()
		visited = []
		flag = 0
		for i in range(1, n):
			if tasks[i] != tasks[i - 1]:
				if tasks[i - 1] not in visited:
					visited.append(tasks[i - 1])
				else:
					flag = 1
					break
		if flag == 0 and tasks[-1] not in visited:
			print('YES')
		else:
			print('NO')
main()


def sol():
	n = int(input())
	s = input()
	if len(s) <= 2:
		return 'YES'
	count = {}
	for x in s:
		count[x] = []
	for i in range(n):
		count[s[i]].append(i)
	for key in count.keys():
		if len(count[key]) != count[key][-1] - count[key][0] + 1:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(sol())


T = int(input())
for i in range(T):
	n = int(input())
	s = input()
	lis = []
	for j in range(n - 1):
		if s[j] in lis:
			print('NO')
			break
		elif s[j] == s[j + 1]:
			pass
		elif s[n - 1] in lis:
			print('NO')
			break
		else:
			lis.append(s[j])
	else:
		print('YES')


b = []
for i in range(int(input())):
	a = str()
	n = int(input())
	a = str(input())
	k = 1
	for x in range(1, n):
		if a[x - 1] != a[x]:
			k = k + 1
	a = ''.join(set(a))
	if len(a) != k:
		b.append('NO')
	else:
		b.append('YES')
print(*b, sep='\n')


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

def int_in():
	return int(input())
for _ in range(int_in()):
	n = int(input())
	s = list(input())
	arr = ['1']
	cheat = 0
	last = '1'
	for i in s:
		if i in arr and last != i:
			cheat = 1
		arr.append(i)
		last = i
	if cheat == 0:
		print('YES')
	else:
		print('NO')


e = int(input())
task = []
for i in range(e):
	day = int(input())
	string = input()
	task.append([day, string])
for x in task:
	temp = []
	flag = True
	temp.append(x[1][0])
	for i in x[1]:
		if i != temp[-1]:
			temp.append(i)
	if len(temp) == len(list(set(temp))):
		print('yes')
	else:
		print('no')


def solve(s: str) -> str:
	aux = ''
	d = {}
	for i in range(len(s)):
		if s[i] not in d:
			d[s[i]] = 1
			aux = s[i]
		elif s[i] in d:
			if aux == s[i]:
				d[s[i]] += 1
			else:
				return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(solve(s))


def checkArray(array):
	result = True
	for (index, item) in enumerate(array[2:]):
		if item in array[:index + 1]:
			result = False
			break
	return result
import re
testcases = int(input())
for test_index in range(testcases):
	length = int(input())
	input_str = input()
	pattern = re.compile('(.)\\1{1,}', re.DOTALL)
	input_str = pattern.sub('\\1', input_str)
	array = list(input_str)
	print('YES' if checkArray(array) else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	letters = set()
	letters.add(s[0])
	for i in range(1, n):
		if s[i] != s[i - 1]:
			if s[i] in letters:
				print('NO')
				break
			else:
				letters.add(s[i])
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	dic = {}
	flag = True
	for j in range(len(s)):
		if s[j] not in dic.keys():
			dic[s[j]] = 0
		elif s[j] in dic.keys() and s[j] != s[j - 1] and (j != 0):
			flag = False
			break
		else:
			continue
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	d = {}
	for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
		d[x] = -1
	flag = 0
	for x in range(n):
		if d[s[x]] == -1:
			d[s[x]] = x
		elif x - d[s[x]] > 1:
			flag = 1
			break
		else:
			d[s[x]] = x
	if flag:
		print('NO')
		continue
	print('YES')


num1 = int(input())
for i in range(num1):
	num2 = int(input())
	list1 = []
	a = input()
	a0 = a[0]
	for j in range(num2):
		if a0 == a[j]:
			continue
		else:
			list1.append(a0)
			a0 = a[j]
	list1.append(a[len(a) - 1])
	set1 = set(list1)
	if len(set1) == len(list1):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	d = list(input())
	w = 0
	for j in d:
		t = d.count(j)
		if d[d.index(j):d.index(j) + t].count(j) != t:
			print('NO')
			w = 1
			break
	if w == 0:
		print('YES')


from itertools import *
for s in [*open(0)][2::2]:
	print('YNEOS'[len([*groupby(s)]) > len({*s})::2])


try:

	def DND(s):
		aplha = []
		for i in range(26):
			aplha.append(-1)
		for i in range(len(s)):
			x = ord(s[i])
			a = ord('A')
			if aplha[x - a] == -1:
				aplha[x - a] = i
			elif i != aplha[x - a] + 1:
				return 'NO'
			elif i == aplha[x - a] + 1:
				aplha[x - a] = i
		return 'YES'
	for t in range(int(input())):
		n = int(input())
		s = input()
		print(DND(s))
except:
	pass


t = int(input())
while t:
	n = int(input())
	tasks = str(input())
	temp = ''
	t_before = '.'
	s = False
	for i in range(0, n):
		if t_before != tasks[i]:
			for j in range(0, len(temp)):
				if tasks[i] == temp[j]:
					s = True
					break
			if not s:
				temp += tasks[i]
				t_before = tasks[i]
			else:
				break
	if s:
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	emp = [s[0]]
	flag = False
	for i in range(1, len(s)):
		if s[i] not in emp:
			emp.append(s[i])
		elif s[i] == s[i - 1]:
			continue
		else:
			print('NO')
			flag = True
			break
	if not flag:
		print('YES')


n = int(input())
r = []
while n > 0:
	finish = []
	q = int(input())
	tareas = input()
	for i in range(q):
		if i == q - 1:
			if tareas[i] in finish:
				r.append('NO')
			else:
				r.append('YES')
		elif tareas[i] in finish:
			r.append('NO')
			break
		elif tareas[i] != tareas[i + 1]:
			finish.append(tareas[i])
	n -= 1
for i in r:
	print(i)


def solve(n, char_str):
	checked = []
	checking = char_str[0]
	for i in char_str:
		if i != checking:
			if i in checked:
				return 'NO'
			checked.append(checking)
			checking = i
	return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	char_str = input()
	print(solve(n, char_str))


for i in range(int(input())):
	(junk, tasks) = (input(), input())
	visited_tasks = []
	ans = 'YES'
	for (i, t) in enumerate(tasks):
		if t in visited_tasks:
			if tasks[i] != tasks[i - 1]:
				ans = 'NO'
				break
		else:
			visited_tasks.append(t)
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	for i in range(1, len(s)):
		if s[i] in s[:i] and s[i] != s[i - 1]:
			print('NO')
			break
	else:
		print('YES')
	t -= 1


t = int(input())
while t:
	n = int(input())
	st1 = input()
	st2 = {}
	st2 = set(st2)
	f = 0
	st2.add(st1[0])
	for i in range(1, n):
		if st1[i] != st1[i - 1]:
			if st1[i] not in st2:
				st2.add(st1[i])
			else:
				f = 1
				break
	if f == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


import sys
from collections import defaultdict
from math import ceil, floor, log10, log2

def solve():
	if n <= 2:
		return 'YES'
	found = set()
	prev = s[0]
	found.add(s[0])
	for i in range(1, n):
		if s[i] != prev:
			if s[i] in found:
				return 'NO'
		found.add(s[i])
		prev = s[i]
	return 'YES'
T = int(input())
for t in range(1, T + 1):
	n = int(input())
	s = input()
	ans = solve()
	print(ans)


for t in range(int(input())):
	n = int(input())
	s = str(input())
	f = 0
	f1 = 0
	for i in range(n):
		for j in range(i + 1, n):
			if s[i] != s[j]:
				f = 1
			if f == 1 and s[i] == s[j]:
				f1 = 1
				break
		f = 0
	if f1 == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for co in range(t):
	n = int(input())
	s = input()
	d = {}
	c = 0
	for i in range(n):
		if s[i] not in d or s[i] == s[i - 1]:
			d[s[i]] = 1
		else:
			print('No')
			c = 1
			break
	if c == 0:
		print('YES')


def main():
	for t in range(int(input())):
		n = int(input())
		s = input()
		flag = True
		i = 0
		while i < n:
			x = s[i]
			while i < n and s[i] == x:
				i += 1
			j = i
			while j < n:
				if s[j] == x:
					flag = False
					break
				j += 1
			if not flag:
				break
		print('YES' if flag else 'NO')
main()


try:
	for t in range(int(input())):
		n = int(input())
		s = input()
		l = []
		l.append(s[0])
		c = 'YES'
		for j in range(1, n):
			if s[j] == s[j - 1]:
				pass
			elif s[j] in l:
				c = 'NO'
			else:
				l.append(s[j])
		print(c)
except EOFError as e:
	pass


def sol(st):
	saw = st[0]
	solution = st[0]
	for i in st[1:]:
		if i != saw:
			solution += i
			saw = i
	return solution
t = int(input())
while t:
	n = int(input())
	st = input()
	st = sol(st)
	if len(set(st)) == len(st):
		print('YES')
	else:
		print('NO')
	t -= 1


T = int(input())
for t in range(1, T + 1):
	n = int(input())
	s = input().strip()
	solved = set()
	cur = None
	sus = False
	for el in s:
		if el == cur:
			continue
		else:
			solved.add(cur)
			if el in solved:
				sus = True
			cur = el
	print('NO' if sus else 'YES')


n = int(input())
for i in range(n):
	length = int(input())
	string = input()
	d = [string[0]]
	cur = string[0]
	ans = True
	for j in range(1, length):
		if string[j] in d:
			if string[j] != cur:
				ans = False
				break
			else:
				cur = string[j]
		else:
			d.append(string[j])
			cur = string[j]
	if ans:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	l = []
	flag = 0
	prev = s[0]
	l.append(prev)
	for i in range(1, n):
		if s[i] not in l:
			l.append(s[i])
		elif s[i] in l and prev != s[i]:
			flag = 1
			break
		prev = s[i]
	if flag == 1:
		print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	s = input()
	prev = s[0]
	a = str(s[0])
	for i in range(1, len(s)):
		if s[i] != prev:
			prev = s[i]
			if a.find(s[i]) != -1:
				print('NO')
				return
			else:
				a += str(s[i])
	print('YES')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	st = set()
	ans = 'yes'
	for (i, c) in enumerate(s):
		if i == 0:
			continue
		if c in st:
			ans = 'no'
		if c != s[i - 1]:
			if s[i - 1] not in st:
				st.add(s[i - 1])
	print(ans)


def sol(s):
	for _ in range(len(s)):
		if s[_] * s.count(s[_]) not in s:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	n = input()
	s = input()
	print(sol(s))


def solve():
	N = int(input())
	tasks = input()
	done = set()
	for x in range(1, N):
		(a, b) = (tasks[x - 1], tasks[x])
		if b in done:
			return 'NO'
		if b == a:
			pass
		else:
			done.add(a)
	return 'YES'
T = int(input())
for _ in range(T):
	print(solve())


import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def npr(n, r):
	return factorial(n) % mod // (factorial(n - r) % mod) if n >= r else 0

def ncr(n, r):
	return factorial(n) % mod // (factorial(r) % mod * (factorial(n - r) % mod)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans

def sumi(n):
	ans = 0
	if len(n) > 1:
		for x in n:
			ans += int(x)
		return ans
	else:
		return int(n)
karmanya = int(input())
while karmanya != 0:
	karmanya -= 1
	n = int(input())
	s = list(input())
	ss = [0]
	f = 1
	for i in s:
		if i == ss[-1]:
			continue
		if i in ss:
			f = 0
			break
		else:
			ss.append(i)
	print(decision[f])


num_cases: int = int(input())
for _ in range(num_cases):
	num_days: int = int(input())
	order: str = input()
	s = set()
	s.add(order[0])
	distracted: bool = False
	for i in range(1, len(order)):
		if order[i - 1] != order[i] and order[i] in s:
			distracted = True
			break
		s.add(order[i])
	if distracted:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	l = int(input())
	str = input()
	li = []
	c = 0
	for j in str:
		if j not in li:
			li.append(j)
		elif li[len(li) - 1] == j:
			continue
		else:
			c = 1
			print('NO')
			break
	if c != 1:
		print('YES')


for i in range(int(input())):
	x = int(input())
	s = list(input())
	for j in range(1, x):
		if s[j] in s[:j] and s[j] != s[j - 1]:
			print('NO')
			break
	else:
		print('YES')


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	n = int(input())
	s = input()
	vis = set()
	vis.add(s[0])
	for i in range(1, n):
		if s[i] == s[i - 1]:
			continue
		elif s[i] in vis:
			print('NO')
			return
		else:
			vis.add(s[i])
	print('YES')
for t in range(int(input())):
	charming()


for p in range(int(input())):
	n = int(input())
	s = str(input())
	(d, x) = ({}, '0')
	for a in s:
		if d.get(a) and x != a:
			print('NO')
			break
		else:
			d[a] = 1
		x = a
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	word = input()
	(arr, i) = ([-1 for i in range(26)], 0)
	while i < n:
		if arr[ord(word[i]) - 65] != -1 and i - 1 >= 0 and (word[i] != word[i - 1]):
			print('NO')
			break
		arr[ord(word[i]) - 65] = i
		i += 1
	if i >= n:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = input()
	if len(a) == len(set(a)):
		print('YES')
	elif len(a) != len(set(a)):
		for i in range(len(a) - 1):
			if a[i] == a[i + 1]:
				continue
			elif a[i] in a[i + 1:]:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	l = []
	f = 0
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			if s[i] not in l:
				l.append(s[i])
		if s[i + 1] in l:
			f = 1
	if f:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	solved = set()
	prev = None
	flag = True
	for i in s:
		if prev is not None and prev != i and (i in solved):
			flag = False
		prev = i
		solved.add(i)
	if flag is False:
		print('NO')
	else:
		print('YES')


t = int(input())
for elee in range(t):
	n = int(input())
	st = input()
	lst = list(st)
	for (ind, ite) in enumerate(st):
		if st[ind - 1] != ite and ite in lst[:ind]:
			print('NO')
			break
	else:
		print('YES')


def solve():
	n = int(input())
	str = input()
	for i in range(0, n - 1):
		flag = True
		for j in range(i + 1, n):
			if str[i] != str[j]:
				flag = False
			elif flag == False:
				if str[i] == str[j]:
					print('NO')
					return
	print('YES')
	return
test = int(input())
for i in range(test):
	solve()


tst = int(input())
arr = []
vals = []
for i in range(0, tst):
	ln = int(input())
	s = input()
	vals.append(s)
for lst in vals:
	good = 'YES'
	for i in set(lst):
		one = lst.find(i) + 1
		last = lst.rfind(i) + 1
		if lst.count(i) <= last - one:
			good = 'NO'
			break
	arr.append(good)
for i in arr:
	print(i)


for _ in range(int(input())):
	n = int(input())
	s = input()
	v = set()
	i = 0
	while i < n:
		if s[i] not in v:
			v.add(s[i])
			while i + 1 < n and s[i] == s[i + 1]:
				i += 1
		else:
			break
		i += 1
	if i == n:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = int(input())
	s = input()
	s1 = []
	flag = True
	for j in range(a - 1):
		if s[j + 1] in s1:
			flag = False
			break
		if s[j] != s[j + 1]:
			s1.append(s[j])
	if flag:
		print('YES')
	else:
		print('NO')


for tt in range(int(input())):
	n = int(input())
	a = list(input())
	l = []
	i = 0
	x = 0
	if len(a) == 1:
		print('YES')
		continue
	while i < len(a) - 1:
		a1 = a[i]
		while a[i] == a[i + 1] and i < len(a) - 2:
			a.pop(i)
		if a1 not in l:
			l.append(a1)
		else:
			x = 10
			break
		i += 1
	if a[-1] in l and a[-1] != a[-2]:
		x = 1
	if x == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	d = {}
	flag = 1
	for i in range(n):
		if s[i] not in d:
			d[s[i]] = 1
		elif s[i] != s[i - 1]:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	a = input()
	f = 0
	for i in range(n - 1):
		if a[i + 1] != a[i]:
			if a[i + 1] in a[:i + 1]:
				print('NO')
				f = 1
				break
	if f == 0:
		print('YES')


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	d = {}
	for i in range(n):
		if s[i] in d:
			d[s[i]].append(i)
		else:
			d[s[i]] = [i]
	flag = True
	for i in d:
		if len(d[i]) == 1:
			continue
		else:
			for j in range(1, len(d[i])):
				if abs(d[i][j] - d[i][j - 1]) > 1:
					flag = False
					break
	if not flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	st = set(s[0])
	fl = True
	for j in range(1, n):
		if s[j] != s[j - 1] and s[j] in st:
			print('NO')
			fl = False
			break
		st.add(s[j])
	if fl:
		print('YES')


t = int(input())

def check():
	n = input()
	s = input()
	ls = {}
	for i in range(len(s)):
		if s[i] in ls and i - ls[s[i]] > 1:
			return True
		ls[s[i]] = i
	return False
for _ in range(t):
	if check():
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	output = 'YES'
	str = input()
	str_dict = {}
	for i in range(1, n):
		if str_dict.get(str[i], False):
			output = 'NO'
			break
		if str[i - 1] != str[i]:
			str_dict[str[i - 1]] = True
	print(output)


def task_list(liste):
	tasks = [liste[i] for i in range(0, len(liste) - 1) if liste[i + 1] != liste[i]]
	tasks = tasks + list(liste[-1])
	if len(set(tasks)) == len(tasks):
		return 'YES'
	else:
		return 'NO'
tests = int(input())
for i in range(tests):
	length = int(input())
	print(task_list(str(input())))


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = [s[i] for i in range(n - 1) if s[i] != s[i + 1]]
	a.append(s[-1])
	print('YES' if len(a) == len(set(a)) else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	prev = -1
	b = []
	c = 0
	for i in a:
		if prev != i:
			if i in b:
				c = c + 1
				break
			else:
				b.append(i)
		prev = i
	if c == 0:
		print('Yes')
	else:
		print('No')


def main():
	n = int(input())
	cur = '-'
	a = set()
	for x in input():
		if x != cur:
			if x in a:
				return False
			cur = x
			a.add(x)
	return True
for _ in ' ' * int(input()):
	print('NYOE S'[main()::2])


t = int(input())
for i in range(t):
	l = [0]
	n = int(input())
	s = input()
	for j in range(n):
		d = s[j]
		if l[-1] != d:
			if d in l:
				print('NO')
				f = False
				break
			else:
				l.append(d)
				f = True
	if f:
		print('YES')


def main():
	n = int(input())
	tasks = input()
	d = set()
	prevc = ' '
	for c in tasks:
		if c != prevc:
			if c in d:
				return 'NO'
		d.add(c)
		prevc = c
	return 'YES'
t = int(input())
for i in range(t):
	print(main())


m = int(input())
for t in range(m):
	n = int(input())
	a = input()
	f = 0
	for i in range(1, n):
		if a[i] != a[i - 1] and a[i] in a[0:i]:
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	f = []
	freq = 0
	n = int(input())
	s = input()
	for i in range(n):
		if s[i] not in f:
			f.append(s[i])
		elif s[i] in f:
			if s[i] == s[i - 1]:
				continue
			else:
				freq = 1
				break
	if freq == 0:
		print('YES')
	else:
		print('NO')


def nor(ele, l):
	count = 0
	for i in range(len(l)):
		if ele == l[i]:
			count += 1
	return count
for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = 0
	l = []
	for char in s:
		l.append(char)
	mys = set(l)
	for ele in mys:
		first = l.index(ele)
		last = len(l) - 1 - l[::-1].index(ele)
		occ = nor(ele, l)
		if last - first + 1 != occ:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	string = input()
	count = 0
	f = 0
	for i in range(len(string)):
		for j in range(i + 1, len(string)):
			if string[i] == string[j] and string[j] != string[j - 1]:
				count += 1
	if count >= 1:
		print('NO')
	else:
		print('YES')


from collections import Counter

def polycarp(x):
	b = []
	for i in range(len(x)):
		if i > 0:
			if x[i] == x[i - 1]:
				continue
		b.append(x[i])
	ls = Counter(b)
	for key in ls:
		if ls[key] != 1:
			return 'NO'
	return 'YES'

def foo(x):
	x = x.split()
	for (i, v) in enumerate(x):
		x[i] = int(v)
	return x
i1 = int(input())
ls = []
for a in range(i1):
	r1 = input()
	r2 = input()
	ans = polycarp(r2)
	ls.append(ans)
for j in ls:
	print(j)


t = int(input())
for i in range(t):
	n = int(input())
	string = input()
	found = False
	for j in range(n - 1):
		first = string[j]
		second = string[j + 1]
		if first != second:
			if string[j + 1:].find(first) != -1:
				found = True
	if found == True:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	encontradas = []
	n = int(input())
	h = 0
	letras = input()
	l = letras[0]
	a = True
	encontradas.append(l)
	for joh in range(1, n):
		if letras[joh] != letras[joh - 1] and letras[joh] in encontradas:
			print('NO')
			a = False
			break
		if letras[joh] not in encontradas:
			encontradas.append(letras[joh])
	if a == True:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	str1 = input()
	lst = []
	flag = 0
	lst.append(str1[0])
	for i in range(1, n):
		if str1[i] != str1[i - 1]:
			lst.append(str1[i])
	lst1 = []
	for i in range(0, len(lst)):
		if lst[i] not in lst1:
			lst1.append(lst[i])
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


for x in range(int(input())):
	n = int(input())
	s = input()
	d = {}
	for i in range(n):
		if s[i] not in d:
			d[s[i]] = [i]
		else:
			d[s[i]].append(i)
	flag = 0
	for i in d:
		for j in range(len(d[i]) - 1):
			if d[i][j + 1] - d[i][j] == 1:
				pass
			else:
				flag = 1
				break
	if flag == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	x = s[0]
	for i in range(1, len(s)):
		if s[i - 1] != s[i]:
			x += s[i]
	print('YES' if len(x) == len(set(x)) else 'NO')


def isSuspicious(tasks, n):
	checker = [[0, 0] for _ in range(26)]
	checker[ord(tasks[0]) - ord('A')][0] == 1
	for i in range(1, n):
		if checker[ord(tasks[i]) - ord('A')][1]:
			return 'NO'
		checker[ord(tasks[i]) - ord('A')][0] = 1
		if tasks[i - 1] != tasks[i]:
			checker[ord(tasks[i - 1]) - ord('A')][1] = 1
	return 'YES'
t = int(input())
while t:
	t -= 1
	n = int(input())
	tasks = input()
	print(isSuspicious(tasks, n))


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	used = set([])
	for i in range(n):
		if s[i] in used:
			print('NO')
			break
		elif i == n - 1 or s[i] != s[i + 1]:
			used.add(s[i])
	else:
		print('YES')


n = int(input())
for _ in range(n):
	num = int(input())
	s = input()
	ans = 'YES'
	for i in range(1, len(s)):
		if s[i] in s[:i] and s[i] != s[i - 1]:
			ans = 'NO'
	print(ans)