The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.

In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.

Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.

The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters:

R, G, B — denoting red, green and blue doors, respectively;

r, g, b — denoting red, green and blue keys, respectively.

Each of these six characters appears in the string exactly once.

The knight is standing at the beginning of the hallway — on the left on the map.

Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 720$) — the number of testcases.

Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once.


-----Output-----

For each testcase, print YES if the knight can open all doors. Otherwise, print NO.


-----Examples-----

Input
4
rgbBRG
RgbrBG
bBrRgG
rgRGBb
Output
YES
NO
YES
NO


-----Note-----

In the first testcase, the knight first collects all keys, then opens all doors with them.

In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.

In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.

In the fourth testcase, the knight can't open the blue door.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
def read_single_num():
	return int(input())

def read_nums():
	return [int(x) for x in input().split()]
t = read_single_num()
for i in range(t):
	s = input()
	keys = set()
	nosol = 0
	for ch in s:
		if ch.isupper():
			if ch.lower() not in keys:
				nosol = 1
		else:
			keys.add(ch)
	if not nosol:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	s = input()
	keys = []
	count = 0
	for i in s:
		if i == 'r' or i == 'g' or i == 'b':
			keys.append(i)
		if i == 'R' or i == 'G' or i == 'B':
			if i.lower() in keys:
				count += 1
	if count == 3:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	dic = {'r': 0, 'g': 0, 'b': 0}
	y = 0
	for i in s:
		if i == 'R':
			if dic['r'] == 0:
				y = 1
		elif i == 'r':
			dic['r'] = 1
		if i == 'G':
			if dic['g'] == 0:
				y = 1
		elif i == 'g':
			dic['g'] = 1
		if i == 'B':
			if dic['b'] == 0:
				y = 1
		elif i == 'b':
			dic['b'] = 1
	if y == 0:
		print('YES')
	else:
		print('NO')


def can_open_all_doors(map):
	hasRedDoorKey = False
	hasGreenDoorKey = False
	hasBlueDoorKey = False
	for i in range(len(map)):
		if map[i] == 'R' and hasRedDoorKey == False:
			return 'NO'
		elif map[i] == 'G' and hasGreenDoorKey == False:
			return 'NO'
		elif map[i] == 'B' and hasBlueDoorKey == False:
			return 'NO'
		elif map[i] == 'r':
			hasRedDoorKey = True
		elif map[i] == 'g':
			hasGreenDoorKey = True
		elif map[i] == 'b':
			hasBlueDoorKey = True
	return 'YES'
t = int(input())
for i in range(t):
	map = input()
	print(can_open_all_doors(map))


def solve(s):
	k = []
	for i in s:
		if i in 'rgb':
			k.append(i)
		elif i.lower() not in k:
			return False
	return True
for _ in range(int(input())):
	s = input()
	if solve(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	flag = True
	red_key = False
	green_key = False
	blue_key = False
	for ch in s:
		if ch in ['r', 'g', 'b']:
			if ch == 'r':
				red_key = True
			elif ch == 'g':
				green_key = True
			else:
				blue_key = True
		elif ch in ['R', 'G', 'B']:
			if ch == 'R' and red_key == False or (ch == 'G' and green_key == False) or (ch == 'B' and blue_key == False):
				flag = False
				break
	if flag:
		print('YES')
	else:
		print('NO')


testcases = int(input())
for i in range(testcases):
	s = input()
	(rkey, gkey, bkey) = (0, 0, 0)
	(rdoor, bdoor, gdoor) = (0, 0, 0)
	flag = 0
	for i in range(len(s)):
		if s[i] == 'r':
			rkey = 1
		elif s[i] == 'b':
			bkey = 1
		elif s[i] == 'g':
			gkey = 1
		elif s[i] == 'R' and rkey != 1:
			flag = 1
			break
		elif s[i] == 'G' and gkey != 1:
			flag = 1
			break
		elif s[i] == 'B' and bkey != 1:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


def solve(h):
	keys = []
	for i in h:
		if i.islower():
			keys.append(i)
		elif i.lower() in keys:
			continue
		else:
			return 'NO'
	return 'YES'
for i in range(int(input())):
	h = input()
	print(solve(h))


t = int(input())
for _ in range(t):
	s = input()
	key = set()
	cond = 1
	for i in s:
		if i == 'r' or i == 'b' or i == 'g':
			key.add(i)
		elif i.lower() in key:
			continue
		else:
			cond = 0
			break
	if cond == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = input()
	if s.index('r') < s.index('R') and s.index('g') < s.index('G') and (s.index('b') < s.index('B')):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	h = {'r': 0, 'g': 0, 'b': 0}
	f = True
	for i in s:
		if i == 'R':
			if h['r'] == 0:
				print('NO')
				f = False
				break
			else:
				h['r'] -= 1
		elif i == 'G':
			if h['g'] == 0:
				print('NO')
				f = False
				break
			else:
				h['g'] -= 1
		elif i == 'B':
			if h['b'] == 0:
				print('NO')
				f = False
				break
			else:
				h['b'] -= 1
		else:
			h[i] += 1
	if f:
		print('YES')


t = int(input())
instr = []
for i in range(t):
	instr.append(input())
for i in instr:
	a = ''
	ans = 'YES'
	for j in i:
		if j.islower():
			a += j
		elif j.lower() not in a:
			ans = 'NO'
	print(ans)


def check(s):
	e = []
	k = 0
	for i in s:
		if i.islower():
			e.append(i)
		elif i.lower() in e:
			k += 1
	return k == 3
for _ in range(int(input())):
	print('YES' if check(input()) else 'NO')


for t in range(int(input())):
	x = list(input())
	lt = []
	count = 0
	if x[0] == 'R' or x[0] == 'G' or x[0] == 'B':
		count = 1
	elif x.index('R') < x.index('r') or x.index('G') < x.index('g') or x.index('B') < x.index('b'):
		count = 1
	if count == 1:
		print('NO')
	else:
		print('YES')


def doorsandkeys():
	s1 = []
	for i in s:
		if i.islower():
			s1.append(i)
		elif i.isupper() and i.lower() not in s1:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	s = list(input())
	print(doorsandkeys())


for _ in range(int(input())):
	passage = input()
	check_keys = ['r', 'g', 'b']
	keys = []
	doors = []
	flag = False
	for i in passage:
		if i in check_keys:
			keys.append(i)
		elif i.lower() not in keys:
			flag = True
			break
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	p = s.index('r')
	q = s.index('R')
	r = s.index('g')
	x = s.index('G')
	y = s.index('b')
	z = s.index('B')
	if p < q and r < x and (y < z):
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	t = t - 1
	store = []
	c = 0
	str1 = input()
	for i in str1:
		if i == 'R' or i == 'B' or i == 'G':
			if i.lower() in store:
				continue
			else:
				c = 1
				print('NO')
				break
		else:
			store.append(i)
	if c == 0:
		print('YES')


x = input()
t = int(x)
for _ in range(t):
	k = input()
	capR = k.index('R')
	capG = k.index('G')
	capB = k.index('B')
	smlR = k.index('r')
	smlG = k.index('g')
	smlB = k.index('b')
	count = 0
	if smlR < capR:
		if smlG < capG:
			if smlB < capB:
				print('YES')
				count = 1
	if count == 0:
		print('NO')


t = int(input(''))
ans = []
for i in range(t):
	st = input('')
	if st[0] != 'R' or st[0] != 'G' or st[0] != 'B':
		if st.index('R') > st.index('r') and st.index('G') > st.index('g') and (st.index('B') > st.index('b')):
			ans.append('YES')
		else:
			ans.append('NO')
	else:
		ans.append('NO')
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
from math import ceil, floor, gcd

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

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

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

def st():
	return input().rstrip('\n')

def isPrime(n):
	if n == 1:
		return 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return 0
	return 1
t = inp()
for _ in range(t):
	s = set()
	a = st()
	fl = 1
	for i in a:
		if i == 'r' or i == 'g' or i == 'b':
			s.add(i)
		elif chr(ord(i) + 32) in s:
			pass
		else:
			fl = 0
	if fl:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	l = list(s)
	r = l.index('r')
	g = l.index('g')
	b = l.index('b')
	R = l.index('R')
	G = l.index('G')
	B = l.index('B')
	if r > R or g > G or b > B:
		print('NO')
	else:
		print('YES')


tc = int(input())
for i in range(tc):
	s = input()
	ar = [0, 0, 0]
	l = len(s)
	flag = 1
	for j in range(l):
		if s[j] == 'r':
			ar[0] += 1
		elif s[j] == 'g':
			ar[1] += 1
		elif s[j] == 'b':
			ar[2] += 1
		if s[j] == 'R':
			if ar[0] == 0:
				print('NO')
				flag = 0
				break
		if s[j] == 'G':
			if ar[1] == 0:
				print('NO')
				flag = 0
				break
		if s[j] == 'B':
			if ar[2] == 0:
				print('NO')
				flag = 0
				break
	if flag == 1:
		print('YES')


for _ in range(int(input())):
	s = input()
	a = set()
	cnt = 0
	for i in range(len(s)):
		if s[i] == 'R' and 'r' in a:
			cnt += 1
		elif s[i] == 'B' and 'b' in a:
			cnt += 1
		elif s[i] == 'G' and 'g' in a:
			cnt += 1
		else:
			a.add(s[i])
	if cnt == 3:
		print('YES')
	else:
		print('NO')


def func(S):
	(r, g, b) = (False, False, False)
	for i in S:
		if i == 'r':
			r = True
		elif i == 'g':
			g = True
		elif i == 'b':
			b = True
		elif i == 'R':
			if not r:
				return 'NO'
		elif i == 'G':
			if not g:
				return 'NO'
		elif not b:
			return 'NO'
	return 'YES'
for t in range(int(input())):
	S = input()
	print(func(S))


import math
T = int(input())
for _ in range(T):
	s = input()
	n = len(s)
	RK = 0
	GK = 0
	BK = 0
	for i in range(n):
		if s[i] == 'r':
			for j in range(i, n):
				if s[j] == 'R':
					RK += 1
		if s[i] == 'g':
			for j in range(i, n):
				if s[j] == 'G':
					GK += 1
		if s[i] == 'b':
			for j in range(i, n):
				if s[j] == 'B':
					BK += 1
	if RK == GK and GK == BK and (GK == 1):
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	b = input()
	inv = []
	for i in range(len(b)):
		if b[i].islower():
			inv.append(b[i])
		if b[i].isupper() and b[i].lower() not in inv:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	(r, g, b) = (False, False, False)
	check = True
	for i in s:
		if i == 'R' and r == False:
			check = False
			break
		if i == 'G' and g == False:
			check = False
			break
		if i == 'B' and b == False:
			check = False
			break
		if i == 'g':
			g = True
		if i == 'b':
			b = True
		if i == 'r':
			r = True
	if not check:
		print('NO')
	else:
		print('YES')


a = int(input())
for b in range(a):
	c = list(input())
	if c.index('r') < c.index('R') and c.index('g') < c.index('G') and (c.index('b') < c.index('B')):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	x = input()
	l = []
	for j in x:
		if j in ['r', 'g', 'b']:
			l.append(j)
		elif chr(ord(j) + 32) in l:
			m = True
			continue
		else:
			m = False
			break
	if m:
		print('YES')
	else:
		print('NO')


class solution:

	def __init__(self, s):
		self.s = s
		self.answer = ''

	def calculation(self):
		l = []
		for i in self.s:
			if i.upper() in l:
				self.answer = 'NO'
			else:
				l.append(i)
		if not self.answer:
			self.answer = 'YES'
t = int(input())
for _ in range(t):
	s = input()
	root = solution(s)
	root.calculation()
	print(root.answer)


t = int(input())
for _ in range(t):
	x = {'r': 0, 'g': 0, 'b': 0}
	ans = 'YES'
	s = input()
	for i in s:
		if i in ('R', 'G', 'B') and x[i.lower()] == 0:
			ans = 'NO'
			break
		else:
			x[i] = 1
	print(ans)


for _ in range(int(input())):
	s = input()
	count = 0
	for x in 'RGB':
		if x.lower() in s[:s.index(x)]:
			count += 1
	print('YNEOS'[count != 3::2])


t = int(input())
for i in range(t):
	L = input()
	count = 0
	for x in range(6):
		if L[x] == 'r':
			if 'R' in L[0:x]:
				print('NO')
				break
			else:
				count += 1
		elif L[x] == 'g':
			if 'G' in L[0:x]:
				print('NO')
				break
			else:
				count += 1
		elif L[x] == 'b':
			if 'B' in L[0:x]:
				print('NO')
				break
			else:
				count += 1
		else:
			count += 1
	if count == 6:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	r = False
	g = False
	b = False
	for c in s:
		if c == 'B':
			if not b:
				print('NO')
				break
		elif c == 'b':
			b = True
		elif c == 'G':
			if not g:
				print('NO')
				break
		elif c == 'g':
			g = True
		elif c == 'R':
			if not r:
				print('NO')
				break
		elif c == 'r':
			r = True
	else:
		print('YES')


n = int(input())
for _ in range(n):
	s = input()
	s = list(s)
	r = 0
	g = 0
	b = 0
	flag = True
	for a in range(len(s)):
		if s[a] == 'r':
			r += 1
		elif s[a] == 'g':
			g += 1
		elif s[a] == 'b':
			b += 1
		elif s[a] == 'R':
			r -= 1
			if r < 0:
				flag = False
				break
		elif s[a] == 'G':
			g -= 1
			if g < 0:
				flag = False
				break
		elif s[a] == 'B':
			b -= 1
			if b < 0:
				flag = False
				break
		else:
			continue
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	str = input()
	if str.index('r') < str.index('R') and str.index('b') < str.index('B') and (str.index('g') < str.index('G')):
		print('YES')
	else:
		print('NO')


z = []
k = []
f = 0
u = int(input(''))
for i in range(u):
	z.append(input(''))
for c in z:
	for i in c:
		if i == 'r' or i == 'g' or i == 'b':
			k.append(i)
		elif i == 'R':
			if 'r' not in k:
				print('NO')
				f = 1
				break
		elif i == 'G':
			if 'g' not in k:
				print('NO')
				f = 1
				break
		elif i == 'B':
			if 'b' not in k:
				print('NO')
				f = 1
				break
	if f == 0:
		print('YES')
	k = []
	f = 0


for i in range(int(input())):
	s = input()
	l = ['r', 'g', 'b']
	L = ['R', 'G', 'B']
	for q in range(3):
		if s.index(L[q]) < s.index(l[q]):
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	have = set()
	cancelled = False
	for c in s:
		have.add(c)
		if c in ['R', 'G', 'B']:
			if not c.lower() in have:
				print('NO')
				cancelled = True
		if cancelled:
			break
	if not cancelled:
		print('YES')


import sys

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

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

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

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

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

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')

def solve():
	for _ in range(get_int()):
		s = get_string()
		n = len(s)
		(r, g, b) = (False, False, False)
		ans = 'YES'
		for i in range(n):
			if s[i] == 'r':
				r = True
			elif s[i] == 'g':
				g = True
			elif s[i] == 'b':
				b = True
			elif s[i] == 'R' and (not r):
				ans = 'NO'
			elif s[i] == 'G' and (not g):
				ans = 'No'
			elif s[i] == 'B' and (not b):
				ans = 'NO'
		get_print(ans)
solve()


a = int(input())
for i in range(1, a + 1):
	b = input()
	if b.find('r') < b.find('R') and b.find('g') < b.find('G') and (b.find('b') < b.find('B')):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	d = {'R': False, 'G': False, 'B': False}
	chk = True
	for i in range(len(s)):
		if ord(s[i]) <= 90:
			if d[s[i]] == False:
				print('NO')
				chk = False
				break
		else:
			d[chr(ord(s[i]) - 32)] = True
	if chk:
		print('YES')


testcases = 0
testcases = int(input())
for i in range(testcases):
	inp = input()
	l = []
	answers = []
	for i in range(len(inp)):
		if inp[i].upper() == inp[i]:
			if inp[i].lower() in l:
				answers.append('YES')
			else:
				answers.append('NO')
		if inp[i].lower() == inp[i]:
			l.append(inp[i])
	if not 'NO' in answers:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	lst = input()
	available_keys = []
	for i in lst:
		if i.islower():
			available_keys.append(i)
		elif i.lower() in available_keys:
			continue
		else:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
for i in range(n):
	a = str(input())
	r = a.index('r')
	b = a.index('b')
	g = a.index('g')
	R = a.index('R')
	B = a.index('B')
	G = a.index('G')
	if a[0] != 'R' or a[0] != 'G' or a[0] != 'B':
		if r < R and b < B and (g < G):
			print('YES')
		else:
			print('NO')
	else:
		print('No')


t = int(input())
for i in range(t):
	s = input()
	rIndex = s.index('r')
	gIndex = s.index('g')
	bIndex = s.index('b')
	RIndex = s.index('R')
	GIndex = s.index('G')
	BIndex = s.index('B')
	if rIndex < RIndex and gIndex < GIndex and (bIndex < BIndex):
		print('YES')
	else:
		print('NO')


t = int(input())
for test_case in range(t):
	string = input()
	r = 0
	g = 0
	b = 0
	R = 0
	G = 0
	B = 0
	ok = 1
	for i in range(6):
		if string[i] == 'r':
			r = 1
		elif string[i] == 'g':
			g = 1
		elif string[i] == 'b':
			b = 1
		elif string[i] == 'R':
			if r == 0:
				ok = 0
				break
			else:
				continue
		elif string[i] == 'G':
			if g == 0:
				ok = 0
				break
			else:
				continue
		elif string[i] == 'B':
			if b == 0:
				ok = 0
				break
			else:
				continue
	if ok == 0:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	s = input()
	store = set()
	answ = 'YES'
	for l in s:
		if l.islower():
			store.add(l)
		elif l.lower() in store:
			continue
		else:
			answ = 'NO'
			break
	print(answ)


def solve():
	s = input()
	if s[0] == 'R' or s[0] == 'G' or s[0] == 'B':
		print('NO')
		return
	else:
		d = {}
		for i in range(6):
			d[s[i]] = i
		for (i, k) in d.items():
			if d['R'] < d['r'] or d['G'] < d['g'] or d['B'] < d['b']:
				print('NO')
				return
		print('YES')
for _ in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	a = input()
	red = []
	gren = []
	blue = []
	brojac = 0
	for j in range(len(a)):
		if a[j] == 'r':
			red.append('r')
			brojac += 1
		elif a[j] == 'b':
			blue.append('b')
			brojac += 1
		elif a[j] == 'g':
			gren.append('g')
			brojac += 1
		elif a[j] == 'R':
			if len(red) > 0:
				brojac += 1
				red.pop()
			elif len(red) == 0:
				print('NO')
				break
		elif a[j] == 'G':
			if len(gren) > 0:
				brojac += 1
				gren.pop()
			elif len(gren) == 0:
				print('NO')
				break
		elif a[j] == 'B':
			if len(blue) > 0:
				brojac += 1
				blue.pop()
			elif len(blue) == 0:
				print('NO')
				break
	if brojac == len(a):
		print('YES')


t = int(input())
for i in range(t):
	s = ''
	s = input()
	r = 0
	g = 0
	b = 0
	R = 0
	G = 0
	B = 0
	for j in range(6):
		if s[j] == 'r':
			r = j
		elif s[j] == 'b':
			b = j
		elif s[j] == 'g':
			g = j
		elif s[j] == 'R':
			R = j
		elif s[j] == 'B':
			B = j
		elif s[j] == 'G':
			G = j
	if r < R and b < B and (g < G):
		print('YES')
	else:
		print('NO')


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	a = list(input())
	s = set()
	key = 0
	for i in range(len(a)):
		if a[i] == 'r' or a[i] == 'g' or a[i] == 'b':
			s.add(a[i])
		else:
			if a[i] == 'R':
				c = 'r'
			if a[i] == 'B':
				c = 'b'
			if a[i] == 'G':
				c = 'g'
			if c not in s:
				key = 1
				print('NO')
				break
	if key == 0:
		print('YES')


t = int(input())
ans = []
for i in range(t):
	string = input()
	list1 = list(string)
	count = 0
	doors = ['B', 'R', 'G']
	keys = ['b', 'r', 'g']
	for item in doors:
		if list1.index(item) > list1.index(keys[doors.index(item)]):
			count += 1
		else:
			count += 0
	if count == 3:
		ans.append('YES')
	else:
		ans.append('NO')
for item in ans:
	print(item)


n = int(input())
arr = []
while n:
	s = input()
	arr.append(s)
	n -= 1

def p(s):
	map = {}
	for char in s:
		if char in 'rgb':
			map[char] = True
		elif char == 'B' and 'b' not in map:
			return 'NO'
		elif char == 'R' and 'r' not in map:
			return 'NO'
		elif char == 'G' and 'g' not in map:
			return 'NO'
	return 'YES'
for a in arr:
	print(p(a))


t = int(input())
while t > 0:
	s = str(input())
	if s.find('g') < s.find('G') and s.find('r') < s.find('R') and (s.find('b') < s.find('B')):
		print('YES')
	else:
		print('NO')
	t -= 1


n = int(input())
while n > 0:
	n -= 1
	t = input()
	d = {'r': 0, 'g': 0, 'b': 0}
	f = 1
	s1 = 'rgb'
	s2 = 'RGB'
	cnt = 0
	for i in t:
		if i in s1:
			d[i] += 1
		elif i in s2 and d[i.lower()] == 0:
			f = 0
			break
		else:
			cnt += 1
		if cnt == 3:
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


test = int(input())
for t in range(test):
	str = input()
	max = 3
	(red, green, blue) = (0, 0, 0)
	for j in str:
		if j == 'r':
			red += 1
		elif j == 'g':
			green += 1
		elif j == 'b':
			blue += 1
		elif j == 'R':
			red -= 1
		elif j == 'G':
			green -= 1
		else:
			blue -= 1
		max = min(max, red, green, blue)
	if max < 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	if s.find('r') > s.find('R') or s.find('b') > s.find('B') or s.find('g') > s.find('G'):
		print('NO')
	else:
		print('YES')


ans = ''
for _ in range(int(input())):
	s = input()
	if s.index('r') < s.index('R') and s.index('g') < s.index('G') and (s.index('b') < s.index('B')):
		ans += 'YES\n'
	else:
		ans += 'NO\n'
print(ans)


for i in range(int(input())):
	s = list(input())
	c = 0
	for i in s:
		if i.isupper():
			if s.index(i) < s.index(i.lower()):
				pass
			else:
				c += 1
	if c == 3:
		print('YES')
	else:
		print('NO')


test = int(input())
for i in range(test):
	samp = input()
	for j in range(6):
		if samp[j] in ['r', 'g', 'b']:
			ind = samp.index(samp[j])
			alt = samp.index(samp[j].upper())
			if ind > alt:
				print('NO')
				break
	else:
		print('YES')


t = int(input())
for i in range(t):
	inp = input()
	x = inp.index('R')
	y = inp.index('G')
	z = inp.index('B')
	if x == 0 or y == 0 or z == 0:
		print('NO')
	elif 'r' in inp[:x] and 'g' in inp[:y] and ('b' in inp[:z]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	(R, B, G) = (0, 0, 0)
	(r, b, g) = (0, 0, 0)
	flag = 0
	for i in s:
		if i == 'r':
			r = 1
		elif i == 'b':
			b = 1
		elif i == 'g':
			g = 1
		if i == 'R':
			if r == 0:
				print('NO')
				flag = 1
				break
		if i == 'G':
			if g == 0:
				print('NO')
				flag = 1
				break
		if i == 'B':
			if b == 0:
				print('NO')
				flag = 1
				break
	if not flag:
		print('YES')


t = int(input())
l = []
for i in range(t):
	s = input()
	key = ''
	for j in s:
		if j in 'rgb':
			key += j
		if j in 'RGB':
			if j.lower() not in key:
				l += ['NO']
				break
	else:
		l += ['YES']
for k in l:
	print(k)


t = int(input())
for _ in range(t):
	_input = str(input())
	keys = []
	flag = True
	for i in _input:
		if i.islower():
			keys.append(i)
		elif i.isupper():
			if i.lower() not in keys:
				print('NO')
				flag = False
				break
	if flag:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	keys = dict()
	keys['r'] = 0
	keys['g'] = 0
	keys['b'] = 0
	boo = True
	for ch in s:
		if ch.islower():
			keys[ch] += 1
		elif keys[ch.lower()] == 0:
			boo = False
			print('NO')
			break
	if boo:
		print('YES')


t = int(input())
res = []
for i in range(t):
	x = input()
	l = []
	l[:] = x
	if l.index('r') < l.index('R'):
		if l.index('g') < l.index('G'):
			if l.index('b') < l.index('B'):
				res.append('YES')
			else:
				res.append('NO')
		else:
			res.append('NO')
	else:
		res.append('NO')
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	s = input()
	k = []
	v = True
	for i in s:
		if i == 'B' or i == 'G' or i == 'R':
			if i.lower() not in k:
				print('NO')
				v = False
				break
		else:
			k.append(i)
	if v:
		print('YES')


for _ in range(int(input())):
	a = input()
	(key, door) = ('', '')
	c = 0
	for i in a:
		if i.isupper():
			if i.lower() in key:
				c += 1
		if i.isupper():
			door += i
		else:
			key += i
	if c == 3:
		print('YES')
	else:
		print('NO')


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ws(s):
	sys.stdout.write(s + '\n')

def main():
	s = rs()
	r = 0
	g = 0
	b = 0
	flg = 1
	for i in s:
		if i == 'r':
			r = 1
		elif i == 'g':
			g = 1
		elif i == 'b':
			b = 1
		elif i == 'R' and r == 0:
			flg = 0
			break
		elif i == 'G' and g == 0:
			flg = 0
			break
		elif i == 'B' and b == 0:
			flg = 0
			break
	if flg:
		ws('YES')
	else:
		ws('NO')
t = ri()
for tc in range(1, t + 1):
	main()


import math
for _ in range(int(input())):
	s = input()
	b = [0, 0, 0]
	for i in s:
		if i == 'r':
			if b[0] != -1:
				b[0] = 1
		elif i == 'g':
			if b[1] != -1:
				b[1] = 1
		elif i == 'b':
			if b[2] != -1:
				b[2] = 1
		elif i == 'R' and b[0] == 0:
			b[0] = -1
		elif i == 'G' and b[1] == 0:
			b[1] = -1
		elif i == 'B' and b[2] == 0:
			b[2] = -1
	if sum(b) == 3:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	l = []
	f = 1
	for i in s:
		if ord(i) > 96:
			l.append(i)
		elif chr(ord(i) + 32) not in l:
			print('NO')
			f = 0
			break
	if f:
		print('YES')


for i in range(int(input())):
	x = input()
	c = []
	s = []
	f = True
	for j in x:
		if j.islower():
			s.append(j)
		elif not j.lower() in s:
			f = False
			break
	print('YES') if f else print('NO')


def solve(sequence):
	doors = []
	for i in sequence:
		if i == 'r' or i == 'g' or i == 'b':
			doors.append(i)
		if i == 'R' or i == 'G' or i == 'B':
			check = chr(ord(i) + 32)
			if check not in doors:
				return 'NO'
	else:
		return 'YES'
n = int(input())
for i in range(n):
	print(solve(input()))


def medo():
	collected = []
	for i in a:
		if i.islower():
			collected.append(i)
		elif i.isupper() and i.lower() not in collected:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	a = list(input())
	print(medo())


t = int(input())
for i in range(t):
	s = input()
	x = []
	f = 0
	for k in s:
		if k == 'R' and 'r' in x:
			x.remove('r')
		elif k == 'B' and 'b' in x:
			x.remove('b')
		elif k == 'G' and 'g' in x:
			x.remove('g')
		elif k == 'R' or k == 'G' or k == 'B':
			print('NO')
			f = 1
			break
		else:
			x.append(k)
	if f == 0:
		print('YES')


t = int(input())
while t:
	a = input()
	h = 0
	s1 = -1
	s2 = -1
	s3 = -1
	s4 = -1
	s5 = -1
	s6 = -1
	for i in range(len(a)):
		if a[i] == 'r':
			s1 = i
		elif a[i] == 'R':
			s2 = i
		elif a[i] == 'g':
			s3 = i
		elif a[i] == 'G':
			s4 = i
		elif a[i] == 'b':
			s5 = i
		else:
			s6 = i
	if s1 < s2 and s3 < s4 and (s5 < s6):
		print('YES')
	else:
		print('NO')
	t = t - 1


t = int(input())
for z in range(t):
	s = input()
	l = []
	c = 0
	for i in s:
		if i == 'r' or i == 'g' or i == 'b':
			l.append(i)
		elif i.lower() in l:
			c = c + 1
		else:
			print('NO')
			break
	if c == 3:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	a = s.index('r')
	a1 = s.index('R')
	c = s.index('g')
	c1 = s.index('G')
	d = s.index('b')
	d1 = s.index('B')
	if a1 > a and c1 > c and (d1 > d):
		print('YES')
	else:
		print('NO')


def doors_k(st):
	key_l = ['r', 'g', 'b']
	for item in key_l:
		if st.index(item) > st.index(item.upper()):
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(0, t):
	st = input()
	response = doors_k(st)
	print(f'{response}')


a = int(input())
for i in range(a):
	s = input()
	answer = False
	if s.index('r') < s.index('R'):
		if s.index('g') < s.index('G'):
			if s.index('b') < s.index('B'):
				answer = True
	if answer == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	rk = s.index('r')
	rd = s.index('R')
	bk = s.index('b')
	bd = s.index('B')
	gk = s.index('g')
	gd = s.index('G')
	if rk < rd and bk < bd and (gk < gd):
		print('YES')
	else:
		print('NO')