You are given a string $s$. You have to determine whether it is possible to build the string $s$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.

For example:

aaaabbb can be built as aa $+$ aa $+$ bbb;

bbaaaaabbb can be built as bb $+$ aaa $+$ aa $+$ bbb;

aaaaaa can be built as aa $+$ aa $+$ aa;

abab cannot be built from aa, aaa, bb and/or bbb.


-----Input-----

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

Each test case consists of one line containing the string $s$ ($1 \le |s| \le 50$), consisting of characters a and/or b.


-----Output-----

For each test case, print YES if it is possible to build the string $s$. Otherwise, print NO.

You may print each letter in any case (for example, YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).


-----Examples-----

Input
8
aaaabbb
bbaaaaabbb
aaaaaa
abab
a
b
aaaab
bbaaa
Output
YES
YES
YES
NO
NO
NO
NO
YES


-----Note-----

The first four test cases of the example are described in the statement.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
def solve(s):
	ans = 'YES'
	arr = []
	curr = 0
	last = s[0]
	for i in s:
		if last == i:
			curr += 1
		else:
			arr.append(curr)
			curr = 1
			last = i
	arr.append(curr)
	for i in arr:
		if i < 2:
			return 'NO'
	return 'YES'
t = int(input())
cases = []
for i in range(t):
	cases.append(input())
ans = []
for case in cases:
	ans.append(solve(case))
for answer in ans:
	print(answer)


test = int(input())
for i in range(test):
	string = '_' + str(input()) + '_'
	if '_ab' in string:
		print('NO')
	elif '_ba' in string:
		print('NO')
	elif 'ab_' in string:
		print('NO')
	elif 'ba_' in string:
		print('NO')
	elif 'aba' in string:
		print('NO')
	elif 'bab' in string:
		print('NO')
	elif '_a_' in string:
		print('NO')
	elif '_b_' in string:
		print('NO')
	else:
		print('YES')


import sys, math

def get_intl():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_int():
	return int(sys.stdin.readline().strip())

def get_strl():
	return sys.stdin.readline().strip().split()

def get_str():
	return sys.stdin.readline().strip()

def prt(msg=''):
	if isinstance(msg, list):
		sys.stdout.write(' '.join(map(str, msg)) + '\n')
	else:
		sys.stdout.write(str(msg) + '\n')
sys.setrecursionlimit(100000000)
MOD = 998244353

def solve():
	inp = get_str()
	new = ' ' + inp + ' '
	if ' a ' in new.replace('b', ' ') or ' b ' in new.replace('a', ' '):
		prt('NO')
	else:
		prt('YES')

def main():
	haveTestCases = 1
	testCase = 1
	if haveTestCases:
		testCase = get_int()
	for i in range(testCase):
		solve()
main()


import sys

def solve():
	s = input()
	last = None
	cnt = 4
	for c in s:
		if last == c:
			cnt += 1
		else:
			if cnt <= 1:
				print('NO')
				return
			cnt = 1
			last = c
	if cnt == 1:
		print('NO')
		return
	print('YES')
for _ in range(int(input())):
	solve()


def get_input():
	al = []
	for c in range(int(input())):
		n = input()
		al.append(n)
	return al

def main():
	arr_list = get_input()
	for arr in arr_list:
		num = 0
		value = -1
		t = arr[0]
		for s in arr:
			if s == t:
				num += 1
			elif num == 1:
				value = 'NO'
			else:
				t = s
				num = 1
		if value == -1:
			if num == 1:
				print('NO')
			else:
				print('YES')
		else:
			print(value)
main()


from itertools import groupby
from sys import stdin
from math import log, floor, ceil, gcd
from collections import defaultdict as dd
input = stdin.readline
inp = lambda : int(stdin.readline())
rs = lambda : stdin.readline().strip()

def ra(typ):
	return list(map(typ, stdin.readline().split()))

def rv(typ):
	return map(typ, stdin.readline().split())

def main():
	for _ in range(inp()):
		s = rs()
		ans = True
		for (_, k) in groupby(s):
			if len(list(k)) < 2:
				ans = False
		print('YES' if ans else 'NO')
main()


t = int(input())
lst = []
for e in range(t):
	s = input()
	x = ''
	if len(s) == 1:
		x = 'NO'
	elif s[1] != s[0]:
		x = 'NO'
	elif s[-1] != s[-2]:
		x = 'NO'
	elif 'bab' in s:
		x = 'NO'
	elif 'aba' in s:
		x = 'NO'
	else:
		x = 'YES'
	lst.append(x)
for i in lst:
	print(i)


t = int(input())
while t:
	s = input()
	if s == 'a' or s == 'b':
		print('NO')
	elif 'aba' in s:
		print('NO')
	elif 'bab' in s:
		print('NO')
	elif s[:2] == 'ab' or s[:2] == 'ba':
		print('NO')
	elif s[len(s) - 2:] == 'ba' or s[len(s) - 2:] == 'ab':
		print('NO')
	else:
		print('YES')
	t -= 1


from sys import stdin, stdout

def solve():
	input = stdin.readline().strip()
	with_a = input.split('b')
	for word in with_a:
		if word and word == 'a':
			print('NO')
			return
	with_b = input.split('a')
	for word in with_b:
		if word and word == 'b':
			print('NO')
			return
	print('YES')

def main():
	t = int(stdin.readline())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	s = input()
	if len(s) < 2:
		print('NO')
	elif 'aba' in s or 'bab' in s or s[0] != s[1] or (s[-1] != s[-2]):
		print('NO')
	else:
		print('YES')


n = int(input())
stli = []
stli.clear
for i in range(n):
	stli.append(input())
for st in stli:
	iOK = 1
	iCount = 0
	aa = st[0]
	for sti in st:
		if sti == aa:
			iCount = iCount + 1
		elif iCount >= 2:
			iCount = 1
			aa = sti
		else:
			print('NO')
			iOK = 0
			break
	if iOK == 1:
		if iCount < 2:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	s = input()
	if s.count('a') == 1 or s.count('b') == 1:
		print('NO')
	elif 'aba' in s or 'bab' in s or s[0:2] == 'ab' or (s[0:2] == 'ba') or (s[-2:] == 'ab') or (s[-2:] == 'ba'):
		print('NO')
	else:
		print('YES')


n = int(input())
a = []
ans = []
for i in range(n):
	a.append(input())
for i in range(len(a)):
	t = a[i]
	if len(t) < 2 or (len(t) >= 2 and ('aba' in t or 'bab' in t or (t[0] == 'a' and t[1] == 'b') or (t[0] == 'b' and t[1] == 'a') or (t[-1] == 'b' and t[-2] == 'a') or (t[-1] == 'a' and t[-2] == 'b'))):
		ans.append('NO')
	else:
		ans.append('YES')
for i in range(len(ans)):
	print(ans[i])


number = int(input())
for i in range(number):
	line = input()
	line_a = line.split('b')
	line_b = line.split('a')
	ans = 0
	for elem in line_a:
		if len(elem) == 1:
			ans += 1
			break
	for elem in line_b:
		if len(elem) == 1:
			ans += 1
			break
	if ans == 0:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	s1 = s.split('a')
	s2 = s.split('b')
	if 'b' in s1:
		print('NO')
	elif 'a' in s2:
		print('NO')
	else:
		print('YES')


def solve():
	s = input()
	prev = s[0]
	valid = False
	for c in s[1:]:
		if c == prev:
			valid = True
		elif not valid:
			print('NO')
			return
		else:
			valid = False
		prev = c
	if not valid:
		print('NO')
	else:
		print('YES')
for tc in range(int(input())):
	solve()


t = int(input())
while t > 0:
	a = input()
	n = len(a)
	fl = 0
	cn = 0
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			if cn == 0:
				fl = 1
			cn = 0
		else:
			cn += 1
	if fl == 1 or n == 1 or a[n - 1] != a[n - 2]:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for test in range(t):
	s = input()
	a = 0
	b = 0
	ans = 'YES'
	for i in s:
		if i == 'a':
			a += 1
			if b > 0 and b == 1:
				ans = 'NO'
				break
			b = 0
		if i == 'b':
			b += 1
			if a > 0 and a == 1:
				ans = 'NO'
				break
			a = 0
	if a == 1 or b == 1:
		ans = 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	m = 0
	n = len(s)
	if len(s) == 1:
		print('NO')
	elif s[0] != s[1] or s[n - 2] != s[n - 1]:
		print('NO')
	else:
		for k in range(len(s) - 2):
			if s[k:k + 3] == 'aba' or s[k:k + 3] == 'bab':
				print('NO')
				m = 1
				break
		if m == 0:
			print('YES')


for _ in range(int(input())):
	s = input()
	co = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			co += 1
		elif co > 1:
			co = 1
			continue
		else:
			co = 0
			break
	if co > 1:
		print('YES')
	else:
		print('NO')


def solve():
	s = input()
	if 'bab' in s or 'aba' in s or s.startswith('ab') or s.startswith('ba') or s.endswith('ab') or s.endswith('ba') or (s == 'a') or (s == 'b'):
		print('NO')
	else:
		print('YES')
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	s = input().strip()
	a = [x for x in s.split('b') if x != '']
	b = [x for x in s.split('a') if x != '']
	ans = 'YES'
	for i in a:
		if len(i) < 2:
			ans = 'NO'
			break
	for i in b:
		if len(i) < 2:
			ans = 'NO'
			break
	print(ans)


def solve(s):
	a = 0
	b = 0
	answer = 'YES'
	for i in s:
		if i == 'a':
			a += 1
			if b > 0 and b == 1:
				answer = 'NO'
				break
			b = 0
		if i == 'b':
			b += 1
			if a > 0 and a == 1:
				answer = 'NO'
				break
			a = 0
	if a == 1 or b == 1:
		answer = 'NO'
	print(answer)
t = int(input())
for test in range(t):
	s = input()
	solve(s)


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


def solve():
	a = input()
	aa = list(a.split('b'))
	bb = list(a.split('a'))
	check = 1
	for i in range(len(aa)):
		if aa[i] == 'a':
			check = 0
			break
	for i in range(len(bb)):
		if bb[i] == 'b':
			check = 0
			break
	if check == 1:
		print('YES')
	else:
		print('NO')
for i in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	s = input()
	if 'aba' in s or 'bab' in s or s.endswith('ab') or s.endswith('ba') or s.startswith('ab') or s.startswith('ba') or (len(s) == 1):
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	b = input()
	if 'aba' in b or 'bab' in b or len(b) == 1 or (b[-2:len(b) + 1] == 'ab') or (b[-2:len(b) + 1] == 'ba') or (b[0:2] == 'ab') or (b[0:2] == 'ba'):
		print('NO')
	else:
		print('YES')


from collections import defaultdict
t = int(input())

def checker(n):
	if n == 1:
		return False
	return True

def solve():
	s = input() + 'l'
	cur = 1
	a = []
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			if not checker(cur):
				print('NO')
				return
			cur = 1
		else:
			cur += 1
	print('YES')
for i in range(t):
	solve()


n = int(input())
res = list()
for _ in range(n):
	a = input()
	can = True
	c = 1
	for i in range(1, len(a)):
		if a[i] != a[i - 1]:
			if c < 2:
				can = False
				break
			else:
				c = 1
		else:
			c += 1
	if can and c >= 2:
		res.append('YES')
	else:
		res.append('NO')
for i in range(n):
	print(res[i])


for _ in range(int(input())):
	string = input().strip()
	if len(string) == 1:
		print('NO')
	elif 'aba' in string or 'bab' in string:
		print('NO')
	elif string[:2] in ['ab', 'ba']:
		print('NO')
	elif string[-2:] in ['ab', 'ba']:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	a = s.strip('b').split('b')
	b = s.strip('a').split('a')
	print('NO' if 'a' in a or 'b' in b else 'YES')


from itertools import groupby
for _ in range(int(input())):
	s = input()
	if all((len(list(b)) >= 2 and a in 'ab' for (a, b) in groupby(s))):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(0, t):
	a = input()
	count = 0
	num = 0
	count1 = 0
	num1 = 0
	d = []
	for ele in a:
		if ele == 'a':
			count += 1
			d.append(num)
			num = 0
		elif ele == 'b':
			num += 1
			d.append(count)
			count = 0
	d.append(count)
	d.append(num)
	m = []
	for ele in d:
		if ele != 0:
			m.append(ele)
	for ele in m:
		if ele >= 2:
			count1 += 1
	if count1 == len(m):
		print('YES')
	else:
		print('NO')


tc = int(input())
for _ in range(tc):
	s = input()
	poss = True
	lc = ''
	cnt = 0
	for c in s:
		if c == 'a':
			if lc == 'b':
				if cnt == 1:
					poss = False
					break
				cnt = 1
			else:
				cnt += 1
			lc = 'a'
		else:
			if lc == 'a':
				if cnt == 1:
					poss = False
					break
				cnt = 1
			else:
				cnt += 1
			lc = 'b'
	if cnt == 1:
		poss = False
	print('YES' if poss else 'NO')


t = int(input())
for _ in range(t):
	s = input()
	lst1 = s.split('a')
	lst2 = s.split('b')
	pos = 1
	for x in lst1:
		if len(x) == 1:
			pos = 0
	for x in lst2:
		if len(x) == 1:
			pos = 0
	if pos:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	if len(s) == 1:
		print('NO')
	elif 'ab' in s[:2] or 'ba' in s[:2]:
		print('NO')
	elif 'ab' in s[-2:] or 'ba' in s[-2:]:
		print('NO')
	elif 'aba' in s or 'bab' in s:
		print('NO')
	else:
		print('YES')


t = int(input())
ans = list()
for i in range(0, t):
	l = list(input())
	if len(l) == 1:
		ans.append('NO')
		continue
	for i in range(0, len(l) - 2):
		if l[i] != l[i + 1] and l[i] == l[i + 2]:
			ans.append('NO')
			break
	else:
		if l[-1] != l[-2]:
			ans.append('NO')
		elif l[0] != l[1]:
			ans.append('NO')
		else:
			ans.append('YES')
for s in ans:
	print(s)


n = int(input())
while n:
	n -= 1
	s = input()
	ac = 0
	bc = 0
	f = 0
	for i in s:
		if i == 'a':
			if bc == 1:
				f = 1
				break
			ac += 1
			bc = 0
		else:
			if ac == 1:
				f = 1
				break
			bc += 1
			ac = 0
	if ac == 1 or bc == 1 or f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	if len(s) == 1:
		print('NO')
	else:
		cur = s[0]
		count = 1
		flag = False
		for i in range(1, len(s)):
			if cur != s[i]:
				if count == 1:
					flag = True
					break
				else:
					count = 1
					cur = s[i]
			else:
				count += 1
		if count == 1:
			flag = True
		if flag:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	s = input()
	a = 0
	if len(s) == 1:
		print('NO')
	elif s[-1] != s[-2]:
		print('NO')
	elif s[0] != s[1]:
		print('NO')
	else:
		for k in range(1, len(s)):
			if s[k] == s[k - 1]:
				continue
			elif k < len(s) - 1:
				if s[k] == s[k + 1]:
					continue
				else:
					a = 1
					break
			else:
				a = 1
				break
		if a == 0:
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	s = input()
	ip = True
	if len(s) < 2:
		ip = False
	if ip:
		if s[0] != s[1] or s[-1] != s[-2]:
			ip = False
	if ip:
		for i in range(1, len(s) - 1):
			if s[i - 1] != s[i] and s[i] != s[i + 1]:
				ip = False
				break
	print('YES' if ip else 'NO')


t = int(input())
for _ in range(t):
	s = input()
	result = True
	if len(s) == 1:
		print('NO')
		continue
	if s[0] == 'a' and s[1] == 'b':
		print('NO')
		continue
	if s[-1] == 'a' and s[-2] == 'b':
		print('NO')
		continue
	if s[0] == 'b' and s[1] == 'a':
		print('NO')
		continue
	if s[-1] == 'b' and s[-2] == 'a':
		print('NO')
		continue
	if 'aba' in s or 'bab' in s:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print('NO')
	elif 'bab' in s:
		print('NO')
	elif 'aba' in s:
		print('NO')
	elif s[len(s) - 1] == 'b' and s[len(s) - 2] == 'a':
		print('NO')
	elif s[len(s) - 1] == 'a' and s[len(s) - 2] == 'b':
		print('NO')
	elif s[0] == 'b' and s[1] == 'a':
		print('NO')
	elif s[0] == 'a' and s[1] == 'b':
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	c = 1
	q = 0
	n = len(s)
	if n == 1:
		print('NO')
	else:
		for i in range(1, n):
			if s[i] == s[i - 1]:
				c = c + 1
			elif c < 2:
				print('NO')
				q = 1
				break
			else:
				c = 1
		if c > 1:
			print('YES')
		elif q == 0:
			print('NO')


t = int(input(''))
for z in range(t):
	s = input('')
	a = s.split('b')
	b = s.split('a')
	if 'a' not in a:
		if 'b' not in b:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def build_string(s):
	n = len(s)
	x = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			x += 1
		else:
			if x == 1:
				return 'NO'
			x = 1
	if x == 1:
		return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	s = str(input())
	print(build_string(s))


for _ in range(int(input())):
	s = input()
	k = s.replace('a', ' ')
	f = s.replace('b', ' ')
	flag = True
	for i in k.split():
		if i == 'b':
			flag = False
	for i in f.split():
		if i == 'a':
			flag = False
	print('YES' if flag else 'NO')


t = int(input())
while t > 0:
	s = input()
	val = s[0]
	count = 0
	for i in s:
		if i == val:
			count += 1
		elif count > 1:
			val = i
			count = 1
		else:
			print('NO')
			break
	else:
		if count > 1:
			print('YES')
		else:
			print('NO')
	t = t - 1


def Dist():
	a = input()
	n = len(a)
	if n < 2:
		print('NO')
		return
	elif a[0] != a[1] or a[n - 2] != a[n - 1]:
		print('NO')
		return
	else:
		for i in range(1, n - 2):
			if a[i - 1] != a[i] and a[i] != a[i + 1]:
				print('NO')
				return
	print('YES')
num_iter = int(input())
for _ in range(num_iter):
	Dist()


def input_strings():
	input_data = []
	number_cases = int(input())
	for i in range(number_cases):
		input_data.append(input())
	return input_data

def solution(string):
	string_list = list(string)
	temp_letter = string_list.pop(0)
	string_count = [1]
	for letter in string_list:
		if letter == temp_letter:
			string_count[-1] += 1
		else:
			temp_letter = letter
			string_count.append(1)
	for i in string_count:
		if i <= 1:
			return 'NO'
	return 'YES'
input_data = input_strings()
for string in input_data:
	sol = solution(string)
	print(sol)


def solve(s):
	consa = 0
	consb = 0
	for i in range(len(s)):
		if s[i] == 'a':
			consa += 1
			if consb == 1:
				return 'NO'
			consb = 0
		else:
			consb += 1
			if consa == 1:
				return 'NO'
			consa = 0
	if consa == 1:
		return 'NO'
	if consb == 1:
		return 'NO'
	return 'YES'
T = int(input())
for t in range(T):
	s = input()
	ans = solve(s)
	print(ans)


t = int(input())
for t1 in range(t):
	s = input()
	if len(s) == 1:
		print('NO')
	elif 'aba' in s or 'bab' in s:
		print('NO')
	elif s[len(s) - 1] == 'b' and s[len(s) - 2] == 'a' or (s[len(s) - 1] == 'a' and s[len(s) - 2] == 'b'):
		print('NO')
	elif s[0] == 'b' and s[1] == 'a' or (s[0] == 'a' and s[1] == 'b'):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = input()
	l1 = [len(i) for i in s.split('a')]
	l2 = [len(i) for i in s.split('b')]
	if 1 in l1 + l2:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	ssss = input()
	lll = len(ssss)
	chkkk = 0
	if lll == 1:
		chkkk = 1
	elif ssss[0] != ssss[1] or ssss[lll - 1] != ssss[lll - 2]:
		chkkk = 1
	for i in range(1, lll - 1):
		if ssss[i] != ssss[i - 1] and ssss[i] != ssss[i + 1]:
			chkkk = 1
	if chkkk == 0:
		print('YES')
	else:
		print('NO')


cases = int(input())
for case in range(cases):
	text = input()
	n = len(text)
	current = text[0]
	ind = 1
	count = 1
	output = 'NO'
	flag = True
	check = {2, 3, 4, 5, 6, 7}
	while ind < n:
		if current == text[ind]:
			count += 1
		elif count >= 2:
			count = 1
			current = text[ind]
			output = 'YES'
		else:
			output = 'NO'
			flag = False
			break
		ind += 1
	if flag == True:
		if count >= 2:
			output = 'YES'
		else:
			output = 'NO'
	print(output)


t = int(input())
for i in range(t):
	a = input()
	prev = a[0]
	flag = 0
	loopflag = 0
	count = 1
	for j in range(1, len(a)):
		loopflag = 1
		if prev == a[j]:
			count += 1
		else:
			if count < 2:
				print('NO')
				flag = 1
				break
			count = 1
			prev = a[j]
	if (loopflag == 0 or count < 2) and flag == 0:
		print('NO')
	elif flag == 0:
		print('YES')


def helper():
	t = int(input())
	for i in range(t):
		s = input()
		l = len(s)
		cnt = 1
		curr = s[0]
		y = True
		if l == 1:
			print('NO')
			y = False
		for i in range(1, l):
			if s[i] == s[i - 1]:
				cnt += 1
			elif cnt == 1:
				print('NO')
				y = False
				break
			else:
				cnt = 1
		if y:
			if cnt == 1:
				print('NO')
			else:
				print('YES')
helper()


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


t = int(input())
for i in range(t):
	f = 'YES'
	s = input()
	a = set(s.split('a'))
	b = set(s.split('b'))
	if 'a' in b or 'b' in a:
		f = 'NO'
	print(f)


q = int(input())
for _ in range(q):
	s = input()
	n = len(s)
	p1 = 'aba'
	p2 = 'bab'
	if len(s) == 1:
		print('NO')
	elif p1 in s or p2 in s:
		print('NO')
	elif s.count('a') == 1 or s.count('b') == 1:
		print('NO')
	elif s[0:2] == 'ab' or s[0:2] == 'ba':
		print('NO')
	elif s[n - 2:n] == 'ab' or s[n - 2:n] == 'ba':
		print('NO')
	else:
		print('YES')


def solve():
	a = input()
	c = 0
	n = ''
	for s in a:
		if s != n:
			if c // 2 + -c // 3 + 1 <= 0:
				return 'NO'
			n = s
			c = 1
		else:
			c += 1
	if c // 2 + -c // 3 + 1 <= 0:
		return 'NO'
	else:
		return 'YES'
for _ in [0] * int(input()):
	print(solve())


for _ in range(int(input())):
	s = input()
	l = len(s)
	flag = 0
	for i in range(l - 2):
		if s[i] != s[i + 1]:
			if s[i + 1] == s[i + 2]:
				continue
			else:
				flag = 1
				break
	if l == 1:
		print('NO')
	elif flag == 1:
		print('NO')
	elif s[0] != s[1]:
		print('NO')
	elif s[-1] != s[-2]:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	s = input()
	now = s[0]
	k = 0
	f = True
	for i in s:
		if i == now:
			k += 1
		else:
			if k == 1:
				f = False
				break
			k = 1
			now = i
	if k == 1:
		f = False
	if f:
		print('YES')
	else:
		print('NO')


x = int(input())
for i in range(x):
	s = input()
	c = []
	a = 0
	dem = str()
	for j in s:
		if dem == '':
			pass
		elif j != dem:
			c.append(a)
		a += 1
		dem = j
	c.append(a)
	pre = 0
	ans = 'YES'
	for j in c:
		if j - pre != 1:
			pre = j
			pass
		else:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	if len(s) == 1 or s[0] != s[1] or s[-1] != s[-2]:
		print('NO')
		continue
	done = False
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1] and s[i] != s[i + 1]:
			print('NO')
			done = True
			break
	if not done:
		print('YES')


def eval(string):
	counts = [1]
	first_el = string[0]
	for i in range(1, len(string)):
		if string[i] == first_el:
			counts[-1] += 1
		else:
			first_el = string[i]
			counts.append(1)
	if 1 in counts:
		return 'NO'
	else:
		return 'YES'

def main():
	n = int(input())
	strings = []
	for i in range(n):
		temp = input()
		strings.append(temp)
	for string in strings:
		print(eval(string))
main()


T = int(input())
for K in range(T):
	s = input()
	i = 0
	a = 'YES'
	if len(s) == 1:
		print('NO')
	else:
		if s[0] != s[1]:
			a = 'NO'
		elif s[-2] != s[-1]:
			a = 'NO'
		elif s.__contains__('aba'):
			a = 'NO'
		elif s.__contains__('bab'):
			a = 'NO'
		print(a)


test_case = int(input())
for _ in range(test_case):
	s = input()
	first_element = s[0]
	count = 1
	for i in range(1, len(s)):
		if s[i] == first_element:
			count += 1
		elif count == 1:
			break
		else:
			first_element = s[i]
			count = 1
	if count != 1:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	s = input()
	cnt = 0
	p = False
	if len(s) == 1:
		print('NO')
		continue
	if s[0] != s[1] or s[len(s) - 1] != s[len(s) - 2]:
		print('NO')
		continue
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1] and s[i] != s[i + 1]:
			print('NO')
			p = True
			break
	if p == False:
		print('YES')


def main():
	t = int(input())
	for k in range(t):
		s = input()
		temp = False
		if len(s) == 1:
			print('NO')
		else:
			cnt = 1
			for i in range(1, len(s)):
				if s[i] == s[i - 1]:
					cnt += 1
				elif cnt == 1:
					temp = True
					break
				else:
					cnt = 1
			if temp or cnt == 1:
				print('NO')
			else:
				print('YES')
main()


for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print('NO')
		continue
	p = s[0]
	count = 1
	b = True
	for i in range(1, len(s)):
		if s[i] == p:
			count += 1
		elif count != 1:
			count = 1
			p = s[i]
			pass
		else:
			print('NO')
			b = False
			break
	if b == False:
		continue
	if count != 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	if len(s) < 2:
		print('NO')
	elif s[0] != s[1] or s[-1] != s[-2]:
		print('NO')
	else:
		r = 1
		for i in range(1, len(s) - 1):
			if s[i] != s[i - 1] and s[i] != s[i + 1]:
				print('NO')
				r = 0
				break
		if r:
			print('YES')


n = int(input())
for i in range(n):
	x = input()
	if len(x) == 1:
		print('NO')
	elif 'aba' in x or 'bab' in x:
		print('NO')
	elif x[0] == 'a' and x[1] == 'b':
		print('NO')
	elif x[0] == 'b' and x[1] == 'a':
		print('NO')
	elif x[-1] == 'b' and x[-2] == 'a':
		print('NO')
	elif x[-1] == 'a' and x[-2] == 'b':
		print('NO')
	else:
		print('YES')


import sys
wrong_start_group = ['aba', 'bab', 'abb', 'baa']
wrong_end_group = ['aba', 'bab', 'aab', 'bba']

def execute(s: str):
	if len(s) == 1:
		print('NO')
		return
	if len(s) == 2:
		if s == 'ab' or s == 'ba':
			print('NO')
			return
		else:
			print('YES')
			return
	if s[:3] in wrong_start_group or s[-3:] in wrong_end_group:
		print('NO')
		return
	for i in range(0, len(s) - 2):
		if s[i] != s[i + 1] and s[i + 1] != s[i + 2]:
			print('NO')
			return
	print('YES')
	return
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
	input_s = sys.stdin.readline().rstrip()
	execute(input_s)


test = int(input())
for i in range(test):
	string = input()
	y = string.replace('aa', '1')
	y = y.replace('1a', '2')
	y = y.replace('bb', '3')
	y = y.replace('3b', '4')
	if y.find('a') != -1 or y.find('b') != -1:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	s = input()
	sca = 0
	scb = 0
	if len(s) == 1:
		print('NO')
	elif s[0] == 'a' and s[1] == 'b' or (s[0] == 'b' and s[1] == 'a'):
		print('NO')
	else:
		for i in s:
			if i == 'a':
				sca += 1
				scb = 0
			else:
				scb += 1
				sca = 0
		if sca == 1 or scb == 1:
			print('NO')
		elif sca > 1 or scb > 1:
			if s.find('aba') != -1 or s.find('bab') != -1:
				print('NO')
			else:
				print('YES')
	t -= 1


t = int(input())
odg = []
for i in range(t):
	flag = 0
	s = input()
	ls = len(s)
	if ls == 1:
		odg.append('NO')
	elif ls == 2:
		if 'aa' in s or 'bb' in s:
			odg.append('YES')
		else:
			odg.append('NO')
	else:
		for j in range(1, ls - 1):
			if s[j - 1] != s[j] and s[j + 1] != s[j]:
				odg.append('NO')
				flag = 1
				break
		if flag != 1:
			if s[-1] != s[-2] or s[0] != s[1]:
				odg.append('NO')
			else:
				odg.append('YES')
for i in odg:
	print(i)


tests = int(input())
out = ''
for _ in range(tests):
	s = input()
	if len(s) == 1:
		out += 'NO\n'
		continue
	secLast = ''
	last = s[0]
	count = 0
	for char in s[1:]:
		if char != last and last != secLast:
			break
		(last, secLast) = (char, last)
	else:
		if last == secLast:
			out += 'YES\n'
			continue
	out += 'NO\n'
print(out)


t = int(input())
for i in range(0, t):
	s = input()
	if len(s) == 1 or s == 'ab' or s == 'ba':
		print('NO')
	elif s.find('aba') != -1 or s.find('bab') != -1:
		print('NO')
	elif s.endswith('ab') or s.endswith('ba') or s.startswith('ab') or s.startswith('ba'):
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	s = input()
	a = True
	if len(s) > 1 and s.count('a') != 1 and (s.count('b') != 1):
		if s[-1] == s[-2] and s[0] == s[1]:
			for i in range(1, len(s) - 1):
				if s[i] != s[i + 1] and s[i - 1] == s[i + 1]:
					a = False
					break
		else:
			a = False
	else:
		a = False
	if a:
		print('YES')
	else:
		print('NO')


def judge(s):
	if not s:
		return True
	if len(s) < 2:
		return False
	if s[:2] == 'aa':
		if len(s) > 2 and s[2] == 'a':
			return judge(s[2:]) or judge(s[3:])
		else:
			return judge(s[2:])
	elif s[:2] == 'bb':
		if len(s) > 2 and s[2] == 'b':
			return judge(s[2:]) or judge(s[3:])
		else:
			return judge(s[2:])
	else:
		return False
T = int(input())
for _ in range(T):
	s = input()
	print('YES') if judge(s) else print('NO')


i = int(input())
r = []
for l in range(0, i):
	j = input()
	a = 0
	b = 0
	k = True
	for m in j:
		if m == 'a':
			a += 1
			if b == 1:
				r.append('NO')
				k = False
				break
			b = 0
		if m == 'b':
			b += 1
			if a == 1:
				r.append('NO')
				k = False
				break
			a = 0
	if k == True and a != 1 and (b != 1):
		r.append('YES')
	elif k == True:
		r.append('NO')
	else:
		continue
for i in r:
	print(i)


def func(s):
	a = s[0]
	s += '#'
	c = ''
	d = []
	for i in range(len(s)):
		if s[i] == a:
			c += a
		else:
			if len(c) < 2:
				return 'NO'
			d.append(c)
			c = s[i]
			a = s[i]
	return 'YES'
t = int(input())
for i in range(t):
	s = input()
	print(func(s))


n = int(input())
a = ['ab', 'ba', 'bab', 'aba']
t = ()
for i in range(n):
	str = input()
	if str == 'a' or str == 'b':
		t = t + ('NO',)
	elif str[-1] + str[-2] in a or str[0] + str[1] in a:
		t = t + ('NO',)
	elif 'bab' in str or 'aba' in str:
		t = t + ('NO',)
	else:
		t = t + ('YES',)
for i in t:
	print(i)


def solve():
	s = input()
	for i in s.split('b'):
		if i == '':
			continue
		if i == 'a':
			return 'NO'
	for i in s.split('a'):
		if i == '':
			continue
		if i == 'b':
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


from collections import defaultdict
from itertools import count
import math as m
from operator import le

def get2int():
	p = input().split()
	return (int(p[0]), int(p[1]))

def get3int():
	p = input().split()
	return (int(p[0]), int(p[1]), int(p[2]))

def cinarr():
	arr = []
	for i in input().split():
		arr.append(int(i))
	return arr

def getParity(n):
	parity = 0
	while n:
		parity = ~parity
		n = n & n - 1
	return parity

def solve():
	arr = input()
	n = len(arr)
	p = 1
	if n == 1:
		print('NO')
		return
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			p += 1
			continue
		else:
			if p < 2:
				print('NO')
				return
			p = 1
	if p >= 2:
		print('YES')
	else:
		print('NO')
for case in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	str = input()
	a = 0
	b = 0
	for j in range(len(str)):
		if str[j] == 'a':
			if b == 1:
				break
			b = 0
			a += 1
		else:
			if a == 1:
				break
			a = 0
			b += 1
	if b == 1:
		print('NO')
		continue
	if a == 1:
		print('NO')
		continue
	print('YES')


t = int(input())
for i in range(t):
	s = input()
	sum = 1
	flag = 0
	if len(s) <= 1:
		print('NO')
		continue
	elif s.count('a') == 1 or s.count('b') == 1:
		print('NO')
		continue
	else:
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				sum += 1
			elif sum == 1:
				print('NO')
				flag = 1
				break
			else:
				sum = 1
		n = len(s)
		if s[n - 1] != s[n - 2] and flag != 1:
			print('NO')
			continue
		if flag == 0:
			print('YES')


n = int(input())
while n:
	s = input()
	f = 1
	k = len(s)
	if s.count('b') == 1 or s.count('a') == 1:
		print('NO')
		n -= 1
		continue
	else:
		if s[0] != s[1] or s[k - 1] != s[k - 2]:
			print('NO')
			n -= 1
			continue
		if 'aba' in s or 'bab' in s:
			print('NO')
			n -= 1
			continue
	print('YES')
	n -= 1


t = int(input())
for i in range(t):
	s = input()
	if len(s) == 1:
		print('NO')
		continue
	count = 0
	flag = False
	flag2 = False
	for i in s:
		if not flag:
			char = i
			count += 1
			flag = True
			continue
		elif i == char:
			count += 1
		elif count == 1:
			print('NO')
			flag2 = True
			break
		else:
			char = i
			count = 1
	if count == 1 and (not flag2):
		print('NO')
		continue
	if not flag2:
		print('YES')