Recently, Mishka started noticing that his keyboard malfunctions — maybe it's because he was playing rhythm games too much. Empirically, Mishka has found out that every other time he presses a key, it is registered as if the key was pressed twice. For example, if Mishka types text, the first time he presses a key, exactly one letter is printed; the second time he presses a key, two same letters are printed; the third time he presses a key, one letter is printed; the fourth time he presses a key, two same letters are printed, and so on. Note that the number of times a key was pressed is counted for the whole keyboard, not for each key separately. For example, if Mishka tries to type the word osu, it will be printed on the screen as ossu.

You are given a word consisting of $n$ lowercase Latin letters. You have to determine if it can be printed on Mishka's keyboard or not. You may assume that Mishka cannot delete letters from the word, and every time he presses a key, the new letter (or letters) is appended to the end of the word.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.

The first line of the test case contains one integer $n$ ($1 \le n \le 100$) — the length of the word.

The second line of the test case contains a string $s$ consisting of $n$ lowercase Latin letters — the word that should be checked.


-----Output-----

For each test case, print YES if the word $s$ can be printed on Mishka's keyboard, and NO otherwise.


-----Examples-----

Input
4
4
ossu
2
aa
6
addonn
3
qwe
Output
YES
NO
YES
NO


-----Note-----

In the first test case, Mishka can type the word as follows: press o (one letter o appears at the end of the word), then presses s (two letters s appear at the end of the word), and, finally, press u (one letter appears at the end of the word, making the resulting word ossu).

In the second test case, Mishka can try typing the word as follows: press a (one letter a appears at the end of the word). But if he tries to press a one more time, two letters a will appear at the end of the word, so it is impossible to print the word using his keyboard.

In the fourth test case, Mishka has to start by pressing q. Then, if he presses w, two copies of w will appear at the end of the word, but the third letter should be e instead of w, so the answer is NO.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ok = True
	i = 1
	while i < len(s):
		if i + 1 >= len(s):
			ok = False
			break
		if s[i] != s[i + 1]:
			ok = False
			break
		i += 3
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n % 3 == 2:
		print('NO')
		continue
	dif = 0
	for i in range(0, n - 2, 3):
		if s[i + 1] != s[i + 2]:
			dif = 1
	if dif:
		print('NO')
	else:
		print('YES')


def sol(n, s):
	if n == 1:
		return 'YES'
	if n == 2:
		return 'NO'
	i = 0
	while i < n:
		if i == n - 1:
			return 'YES'
		if i + 1 == n - 1:
			return 'NO'
		if s[i + 1] != s[i + 2]:
			return 'NO'
		i += 3
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(sol(n, s))


l = []
for i in range(2, 101, 3):
	l.append(i)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n in l:
		print('NO')
	else:
		for i in range(1, n, 3):
			if s[i] != s[i + 1]:
				print('NO')
				break
		else:
			print('YES')


def main():
	num = int(input())
	for i in range(num):
		isTrue = True
		numLetter = int(input())
		word = input()
		if numLetter > 1:
			for k in range(0, 100):
				if numLetter == 2 + 3 * k:
					isTrue = False
			for j in range(1, numLetter, 3):
				if j < numLetter - 1:
					if word[j] != word[j + 1]:
						isTrue = False
		if isTrue:
			print('YES')
		else:
			print('NO')
main()


tests = int(input())
for _ in range(tests):
	m = int(input())
	s = input()
	flag = 1
	i = 0
	while i < m:
		if flag == 2:
			if i == m - 1 or s[i] != s[i + 1]:
				print('NO')
				break
		i += flag
		flag = 3 - flag
	else:
		print('YES')


for _ in range(int(input())):
	(N, S) = (int(input()), input())
	k = 0
	i = 0
	while i < N:
		if k % 2 and i == N - 1:
			print('NO')
			break
		elif k % 2 and i < N - 1:
			if S[i] != S[i + 1]:
				print('NO')
				break
			else:
				i += 1
		i += 1
		k += 1
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	res = 'YES'
	for j in range(2, len(s), 3):
		if s[j] != s[j - 1]:
			res = 'NO'
			break
	if res == 'YES' and (n % 3 == 1 or n % 3 == 0):
		print(res)
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input() + '@'
	b = True
	for j in range(1, n):
		if j % 3 == 1:
			b &= s[j] == s[j + 1]
	if b:
		print('YES')
	else:
		print('NO')


import sys
s = sys.stdin.read()

def solve(data, lenght):
	if lenght % 3 != 0 and (lenght - 1) % 3 != 0:
		print('NO')
		return
	for i in range(int(lenght // 3)):
		if data[i * 3 + 1] != data[i * 3 + 2]:
			print('NO')
			return
	print('YES')
lines = s.split('\n')
cell_data = []
for index in range(1, len(lines) - 2, 2):
	lenght = int(lines[index])
	data = lines[index + 1]
	solve(data, lenght)


answer = []
n = int(input())
for _ in range(n):
	a = int(input())
	s = input()
	i = 0
	result = 'YES'
	while True:
		if i >= a:
			break
		if i % 3 == 0:
			i += 1
			continue
		if i + 1 == a:
			result = 'NO'
			break
		elif s[i] == s[i + 1]:
			i += 2
			continue
		else:
			result = 'NO'
			break
	answer.append(result)
for ans in answer:
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	st = input()
	if n % 3 == 2:
		print('NO')
		continue
	else:
		for i in range(n // 3):
			if st[3 * i + 1] != st[3 * i + 2]:
				print('NO')
				break
		else:
			print('YES')


for i in range(int(input())):
	a = int(input())
	c = input()
	b = 'True'
	i = 0
	while i < a and b:
		if i == 0:
			i = i + 1
		elif i % 3 == 1:
			if i + 1 < a:
				if c[i] == c[i + 1]:
					i = i + 1
				else:
					b = 'False'
					i = i + 1
			else:
				b = 'False'
				i = i + 1
		else:
			i = i + 1
	if b == 'True':
		print('YES')
	else:
		print('NO')


import sys
rd = sys.stdin.readline
for _ in range(int(rd())):
	n = int(rd())
	s = rd().strip()
	i = 0
	if n % 3 == 2:
		print('NO')
	else:
		while i < n:
			if i % 3 == 1:
				if s[i] != s[i + 1]:
					print('NO')
					break
				i += 1
			i += 1
		else:
			print('YES')


for i in range(int(input())):
	n = int(input())
	s = input()
	flag = True
	j = 1
	if n == 2:
		flag = False
	elif n % 3 == 0 or (n - 1) % 3 == 0:
		while j + 1 < n:
			if s[j] != s[j + 1]:
				flag = False
				break
			else:
				j += 3
	else:
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')


for qwq in range(int(input())):
	n = int(input())
	s = input()
	print('YES' if n % 3 != 2 and (not False in [s[i * 3 + 1] == s[i * 3 + 2] for i in range(n // 3)]) else 'NO')


n = int(input())

def check(s, num):
	for j in range(1, num, 3):
		if j + 1 == num:
			return False
		if s[j] != s[j + 1]:
			return False
	return True
for i in range(n):
	num = int(input())
	s = input()
	if check(s, num) == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	j = 0
	while j < n:
		var = 0
		if j != 0 and (j - 1) % 3 == 0:
			if j + 1 < n:
				if s[j] != s[j + 1]:
					print('NO')
					break
				else:
					var = 1
			else:
				print('NO')
				break
			if var == 0:
				j += 1
			elif var == 1:
				j += 2
		else:
			j += 1
	else:
		print('YES')


t = int(input())
for x in range(t):
	n = int(input())
	w = input()
	a = 1
	if n % 3 == 2:
		a = 0
	else:
		for i in range(n - 1):
			z = i % 3
			if z == 1:
				if w[i] != w[i + 1]:
					a = 0
	if a == 1:
		print('YES')
	if a == 0:
		print('NO')


for t in range(int(input())):
	l = int(input())
	s = input()
	if l % 3 == 2:
		print('NO')
		continue
	elif l % 3 != 2:
		for i in range(1, l, 3):
			if s[i] != s[i + 1]:
				print('NO')
				break
		else:
			print('YES')


for i in range(int(input())):
	n = int(input())
	text = input()
	if n % 3 == 2:
		print('NO')
	else:
		ans = 'YES'
		for i in range(n // 3):
			if text[i * 3 + 1] != text[i * 3 + 2]:
				ans = 'NO'
				break
		print(ans)


t = int(input())
res = ''
for i in range(t):
	n = int(input())
	s = str(input())
	j = 1
	a = 0
	while j < n - 1:
		if s[j] != s[j + 1]:
			res = res + 'NO\n'
			a = 1
			break
		j = j + 3
	if j + 1 == n:
		res = res + 'NO\n'
		a = 1
	if a == 0:
		res = res + 'YES\n'
print(res)


def mishkaword(word):
	double = 0
	result = True
	i = 0
	while result:
		if double % 2 == 1 and i + 1 < len(word):
			result = word[i] == word[i + 1]
			i += 1
		elif double % 2 == 1 and i + 1 == len(word):
			result = False
			break
		i += 1
		double += 1
		if i == len(word):
			break
	return result
n = int(input())
words = []
for i in range(n):
	n1 = int(input())
	words.append(input())
for word in words:
	if mishkaword(word):
		print('YES')
	else:
		print('NO')


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	if n % 3 == 0:
		a = 0
		b = a + 2
		while b <= n - 1:
			ss = s[a:b + 1]
			if ss[1] != ss[2]:
				print('NO')
				break
			else:
				a = b + 1
				b = a + 2
		else:
			print('YES')
	elif n % 3 == 1:
		a = 0
		b = a + 2
		while b <= n - 2:
			ss = s[a:b + 1]
			if ss[1] != ss[2]:
				print('NO')
				break
			else:
				a = b + 1
				b = a + 2
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = int(input())
	z = input()
	if l % 3 == 2:
		print('NO')
		continue
	p = 'YES'
	for i in range(l):
		if i % 3 == 2:
			if z[i - 1] != z[i]:
				p = 'NO'
				break
	print(p)


def func(s, n):
	if n % 3 == 2:
		return 'NO'
	i = 1
	while i < n:
		if s[i] != s[i + 1]:
			return 'NO'
		i += 3
	return 'YES'

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		print(func(s, n))
main()


for t in range(int(input())):
	n = int(input())
	s = input()
	if len(s) % 3 == 2:
		print('NO')
		continue
	for i in range(len(s)):
		if i % 3 == 1 and s[i] != s[i + 1]:
			print('NO')
			break
	else:
		print('YES')


import sys
number_of_tests = int(input())
for i in range(number_of_tests):
	length = int(input())
	sequence = list(input())
	if length % 3 == 2:
		sys.stdout.write('NO')
		print('')
		continue
	elif length % 3 == 1:
		j = 0
		while 3 * j + 2 <= length - 2:
			if sequence[3 * j + 1] != sequence[3 * j + 2]:
				break
			else:
				j += 1
		if 3 * j + 2 == length + 1:
			sys.stdout.write('YES')
		else:
			sys.stdout.write('NO')
		print('')
	else:
		j = 0
		while 3 * j + 2 <= length - 1:
			if sequence[3 * j + 1] != sequence[3 * j + 2]:
				break
			else:
				j += 1
		if 3 * j + 2 == length + 2:
			sys.stdout.write('YES')
		else:
			sys.stdout.write('NO')
		print('')


def chk():
	x = int(input())
	y = input()
	z = ''
	i = 0
	while i < x:
		if i == 0 or i % 3 == 0:
			z += y[i]
			i += 1
		else:
			k = y[i] + y[i]
			z += k
			i += 2
	if y == z:
		print('YES')
	else:
		print('NO')
x = int(input())
for i in range(x):
	chk()


cases = int(input().rstrip())
inp = []
for i in range(cases):
	_ = input().rstrip()
	stringv = input().rstrip()
	inp.append(stringv)

def solve(a):
	if len(a) == 0:
		return 'YES'
	a = a[1:]
	if len(a) == 1:
		return 'NO'
	if len(a) == 0:
		return 'YES'
	if a[0] == a[1]:
		if len(a) == 2:
			return 'YES'
		return solve(a[2:])
	else:
		return 'NO'
for i in range(cases):
	print(solve(inp[i]))


for _ in range(int(input())):
	n = int(input())
	s = input()
	b = True
	if n % 3 == 2:
		print('NO')
		continue
	if n == 1:
		print('YES')
		continue
	for i in range(1, n, 3):
		if s[i] != s[i + 1]:
			b = False
			break
	if b:
		print('YES')
	else:
		print('NO')


t = int(input())
loo = []
for i in range(t):
	n = int(input())
	text = input()
	length = len(text)
	o = 'YES'
	if length % 3 == 2:
		loo.append('NO')
	elif length % 3 == 0:
		for j in range(0, length, 3):
			if text[j + 1] != text[j + 2]:
				o = 'NO'
				break
		loo.append(o)
	else:
		for j in range(0, length - 1, 3):
			if text[j + 1] != text[j + 2]:
				o = 'NO'
				break
		loo.append(o)
for i in range(t):
	print(loo[i])


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	ans = True
	turn = False
	while i < n:
		if turn:
			twice = s[i:i + 2]
			if len(twice) != 2 or twice[0] != twice[1]:
				ans = False
				break
		i += 2 if turn else 1
		turn = not turn
	print('YES' if ans else 'NO')


for _ in range(int(input())):
	n = int(input())
	arr = input()
	top = 0
	flag = False
	while top < len(arr) - 1:
		if top + 2 == len(arr) or arr[top + 1] != arr[top + 2]:
			flag = True
			print('NO')
			break
		top += 3
	if not flag:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0

	def check(s):
		i = 0
		k = len(s)
		if k == 1:
			return True
		elif k % 3 == 2:
			return False
		while i < k - 2:
			if i % 3 == 0:
				if s[i + 1] != s[i + 2]:
					return False
			i += 1
		return True
	if check(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	i = 0
	answer = 'YES'
	while i < n:
		if i % 3 == 0:
			i += 1
		elif i % 3 == 1:
			if i + 1 > n - 1:
				answer = 'NO'
				break
			elif s[i] == s[i + 1]:
				i += 1
			else:
				answer = 'NO'
				break
		else:
			i += 1
	print(answer)


for _ in range(int(input())):
	input()
	k = input()
	yes = len(k) % 3 != 2
	yes &= k[1::3] == k[2::3]
	print('YES' if yes else 'NO')


for i in range(int(input())):
	n = int(input())
	a = input()
	f = False
	for i in range(1, n, 3):
		if i + 1 >= n or a[i] != a[i + 1]:
			f = True
			break
	if f:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	k = 0
	flag = 0
	a = []
	x = 0
	xx = 0
	for i in range(1, n + 1):
		if x == 1:
			a.append(xx + 2)
			xx += 2
			x = 0
		else:
			a.append(xx + 1)
			xx += 1
			x = 1
	i = 0
	while i < n:
		if i == n - 1:
			break
		if k == 1:
			if s[i] != s[i + 1]:
				flag = -1
				break
			i += 2
			k = 0
		else:
			k = 1
			i += 1
	if flag == 0 and len(s) in a:
		print('YES')
	else:
		print('NO')


n = int(input())
a = []
for _ in range(2 * n):
	a.append(input())
for i in range(0, 2 * n, 2):
	num = int(a[i])
	word = str(a[i + 1]) + ' '
	s = 0
	for j in range(num):
		if j > 0 and j % 3 == 1:
			if word[j] == word[j + 1]:
				s += 1
	if s == (1 + num) // 3:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	ans = ''
	if (n - 2) % 3 == 0:
		ans = 'NO'
	x = 0
	c = 1
	if ans != 'NO':
		while x != n:
			if c % 2 == 0:
				if s[x] == s[x + 1]:
					x += 2
				else:
					ans = 'NO'
					break
			else:
				x += 1
			c += 1
	if ans == 'NO':
		print(ans)
	else:
		print('YES')


def solution():
	n = int(input())
	s = str(input())
	if n % 3 == 2:
		print('NO')
		return
	for j in range(n // 3):
		if s[3 * j + 1] != s[3 * j + 2]:
			print('NO')
			return
	print('YES')
t = int(input())
for i in range(t):
	solution()


t = int(input())
for t0 in range(t):
	n = input()
	line = input()
	if len(line) % 3 == 2:
		print('NO')
		continue
	ok = True
	for (index, c) in enumerate(list(line)):
		if index % 3 == 2:
			if not c == line[index - 1]:
				ok = False
				break
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = input()
	if n % 3 == 2:
		print('NO')
		continue
	s = 1
	for i in range(1, n - 1, 3):
		if arr[i] != arr[i + 1]:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n == 1:
		print('YES')
	else:
		for i in range(1, n, 3):
			if i + 1 > n - 1 or s[i] != s[i + 1]:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
x = 0
while x < t:
	l = int(input())
	f = False
	s = input()
	for i in range(1, l, 3):
		if i + 1 >= l or s[i] != s[i + 1]:
			f = True
			break
	if f:
		print('NO')
	else:
		print('YES')
	x = x + 1


t = int(input(''))
for z in range(t):
	n = int(input(''))
	s = input('')
	k = 0
	if n % 3 == 2:
		k = 1
	else:
		p = 0
		while p != n:
			if p % 3 == 0:
				p += 1
			elif s[p] == s[p + 1]:
				p += 2
			else:
				k = 1
				break
	if k == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 1
	i = 0
	while i < n:
		if cnt % 2 == 0:
			if i + 1 >= n or s[i] != s[i + 1]:
				print('NO')
				break
			cnt += 1
			i += 2
		else:
			i += 1
			cnt += 1
	else:
		print('YES')


x = int(input())
for i in range(x):
	n = int(input())
	s = input()
	if n % 3 == 2:
		print('NO')
		continue
	flag = 1
	for i in range(1, n, 3):
		if s[i] != s[i + 1]:
			flag = 0
	if flag == 0:
		print('NO')
	elif flag == 1:
		print('YES')


import itertools
import sys
from collections import defaultdict
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 solve(n, s):
	if n == 3:
		if s[1] == s[2]:
			print('YES')
		else:
			print('NO')
		return
	i = 1
	while i < n:
		if s[i] != s[i + 1]:
			print('NO')
			return
		i += 3
	print('YES')
for i in range(inp()):
	n = inp()
	s = input()
	solve(n, s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ok = 1
	for i in range(1, n, 3):
		if len(s[i:i + 2]) == 2 and len(set(s[i:i + 2])) == 2:
			ok = 0
			break
		elif len(s[i:i + 2]) == 1:
			ok = 0
			break
	print('YES' if ok else 'NO')


def solve(n, nums):
	(i, count) = (0, 1)
	while i < n:
		if count % 2 == 0:
			if i + 1 == n:
				return 'NO'
			if nums[i] == nums[i + 1]:
				i += 2
			else:
				return 'NO'
		else:
			i += 1
		count += 1
	return 'YES'
T = int(input())
for t in range(T):
	n = int(input())
	nums = input()
	print(solve(n, nums))


t = int(input())
lista = []
for x in range(t):
	n = int(input())
	s = input()
	if n % 3 == 2:
		lista.append('NO')
	else:
		suma = 0
		for y in range(n):
			if (y + 1) % 3 == 2 and s[y] == s[y + 1]:
				suma += 1
		if suma == len(s) // 3:
			lista.append('YES')
		else:
			lista.append('NO')
for x in lista:
	print(x)


for t in range(int(input())):
	n = int(input())
	p = input()
	if n % 2 == 2:
		ans = 'NO'
	else:
		ans = 'YES' if p[1::3] == p[2::3] else 'NO'
	print(ans)


l = int(input())
for i in range(0, l):
	n = int(input())
	t = input()
	if n % 3 == 2:
		print('NO')
	elif n == 1:
		print('YES')
	elif n % 3 == 0:
		for j in range(1, n, 3):
			if t[j] == t[j + 1]:
				k = True
				continue
			else:
				k = False
				break
		if k == True:
			print('YES')
		if k == False:
			print('NO')
	elif n % 3 == 1 and n != 1:
		for j in range(1, n - 1, 3):
			if t[j] == t[j + 1]:
				k = True
				continue
			else:
				k = False
				break
		if k == True:
			print('YES')
		if k == False:
			print('NO')


import sys

def solve():
	input = sys.stdin.readline
	n = int(input())
	s = input()
	flag = True
	i = 0
	for i in range(1, n, 3):
		if i + 1 < n:
			if s[i] != s[i + 1]:
				flag = False
				break
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for i in range(t):
	l = int(input())
	s = input()
	j = 0
	flag = 0
	while j < l:
		if j % 3 == 0:
			j += 1
			continue
		elif j % 3 == 1:
			if j + 1 < l and s[j] == s[j + 1]:
				j += 2
			else:
				flag = 1
				break
	if flag == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for x in range(t):
	n = int(input())
	string = input()
	if n % 3 == 2:
		print('NO')
		continue
	Y_N = 'YES'
	for i in range(1, len(string)):
		if i % 3 == 2 and string[i] != string[i - 1]:
			Y_N = 'NO'
			break
	print(Y_N)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	h = 0
	l = []
	for i in s:
		l.append(i)
	if len(l) == 2:
		print('NO')
	elif len(l) == 1:
		print('YES')
	else:
		for i in l:
			if len(l) >= 3:
				k = l[:3]
				l = l[3:]
				if k[1] == k[2]:
					c += 1
				else:
					c = 0
					print('NO')
					break
			elif len(l) == 2:
				c = 0
				print('NO')
				break
			else:
				c += 1
	if c:
		print('YES')


t = int(input())
for _ in range(t):
	k = int(input())
	s = input()
	m = k // 3
	i = 0
	ans = 0
	while i < m * 3:
		if s[i + 1] == s[i + 2]:
			ans = ans + 1
		i = i + 3
	if ans == m and (k % 3 == 1 or k % 3 == 0):
		print('YES')
	else:
		print('NO')


case_num = int(input(''))
cur_case = 0
while cur_case < case_num:
	s_len = int(input(''))
	s = input('')
	solved = False
	if (s_len + 1) % 3 == 0:
		print('NO')
		cur_case += 1
		continue
	for i in range(s_len):
		check_last = (i + 1) % 3 == 0
		if check_last and s[i] != s[i - 1]:
			print('NO')
			solved = True
			break
	if not solved:
		print('YES')
	cur_case += 1


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n % 3 == 2:
		print('NO')
		continue
	stop = 0
	for i in range(1, n - 1, 3):
		if s[i] != s[i + 1]:
			stop = 1
			break
	if stop == 1:
		print('NO')
	else:
		print('YES')


cases = int(input())
for i in range(cases):
	length = int(input())
	word = input()
	if length % 3 == 2:
		print('NO')
		imp = True
		continue
	imp = False
	for k in range(length):
		if k % 3 == 2:
			if word[k] != word[k - 1]:
				print('NO')
				imp = True
				break
	if not imp:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = input()
	j = 0
	while j < n:
		if j % 3 == 0:
			j = j + 1
		elif j < n - 1:
			if l[j] != l[j + 1]:
				print('NO')
				break
			else:
				j = j + 2
		else:
			print('NO')
			break
	else:
		print('YES')


for i in range(int(input())):
	_ = input()
	massive = [i for i in input()]
	check_ = False
	word = 1
	res = 'YES'
	for (index, letter) in enumerate(massive):
		if check_:
			check_ = False
			continue
		if word % 2 == 0:
			try:
				if letter == massive[index + 1]:
					check_ = True
				else:
					res = 'NO'
					break
			except IndexError:
				res = 'NO'
				break
		word += 1
	print(res)


import math

def solve():
	size = int(input())
	inputString = input()
	possible = True
	if len(inputString) % 3 == 2:
		print('NO')
		return
	i = 1
	while i <= len(inputString) - 2:
		if inputString[i] != inputString[i + 1]:
			possible = False
			break
		i = i + 3
	if possible != True:
		print('NO')
	else:
		print('YES')
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n % 3 == 0 or n % 3 == 1:
		c = 1
		an = 'YES'
		for i in range(n):
			if i == c:
				if s[i] != s[i + 1]:
					an = 'NO'
					break
				c += 3
		print(an)
	else:
		print('NO')


n = int(input())
t = []
for _ in range(n):
	l = int(input())
	ok = True
	s = str(input())
	if len(s) % 3 == 2:
		t.append('NO')
	else:
		for i in range(0, len(s)):
			if i % 3 == 2:
				if s[i] != s[i - 1]:
					t.append('NO')
					ok = False
					break
		if ok:
			t.append('YES')
for e in t:
	print(e)


def solution(s):
	if len(s) % 3 != 2:
		for i in range(len(s)):
			if i % 3 == 2:
				if s[i] != s[i - 1]:
					return 'NO'
		return 'YES'
	return 'NO'
val = int(input())
for i in range(val):
	buff = int(input())
	str_val = input()
	print(solution(str_val))


def work():
	t = int(input())
	while t > 0:
		t = t - 1
		i = int(input())
		str = input()
		if i % 3 == 2:
			print('NO')
			continue
		k = check(i, str)
		if k == 0:
			print('NO')
		if k == 1:
			print('YES')

def check(n, str):
	l = list(str)
	c = 0
	k = 1
	for i in range(0, n - 1, 1):
		if l[i] == l[i + 1] and c != 1 and (k % 2 == 0):
			c = 1
			k = k + 1
			continue
		elif k % 2 == 0:
			return 0
		elif c == 1:
			c = 0
			continue
		else:
			k += 1
	else:
		return 1
	return 0
work()


def solve(l, s):
	if l % 3 == 2:
		return 'NO'
	for i in range(2, l, 3):
		if s[i - 1] != s[i]:
			return 'NO'
	return 'YES'

def test():
	t = int(input())
	for j in range(t):
		l = int(input())
		s = input()
		print(solve(l, s))
test()


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	flag = True
	turn = 0
	while s:
		ne = s.pop(0)
		if turn:
			if s:
				ne2 = s.pop(0)
			else:
				flag = False
			if ne != ne2:
				flag = False
				break
		turn = 1 - turn
	print('YES' if flag else 'NO')


for _ in range(int(input())):
	a = int(input())
	b = input()
	if a % 3 == 2:
		print('NO')
		continue
	ans = 'YES'
	for i in range(a):
		if i % 3 == 2:
			if b[i - 1] != b[i]:
				ans = 'NO'
				break
	print(ans)