One day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange.
Now he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same color.

-----Input-----
- The first line of the input contains an integer T denoting the number of test cases.
- A single line of each test case contains six words denoting the colors of painted sides in the order: front, back, left, right, top and bottom, respectively.

-----Output-----
For each test case, output a single line containing the word "YES" or "NO" (without quotes) corresponding to the answer of the problem.

-----Constraints-----
- 1 ≤ T ≤  50000 
- Each color will be from the list {"black", "blue", "red", "green", "yellow", "orange"}

-----Subtasks-----
Subtask 1: (25 points)
- 1 ≤ T ≤  12000 
- For each test case there will be at most three different colors

Subtask 2: (75 points)
- Original constraints

-----Example-----
Input:
2
blue yellow green orange black green
green yellow green orange black green

Output:
NO
YES

-----Explanation-----

Example case 1.
There are no three sides with the same color.

Example case 2.
In this test case, the front, bottom and left sides are green (see picture).

Source: codechef | Difficulty: EASY
Tags: Implementation

Ad-hoc


Solutions:
for _ in range(int(input())):
	s = list(map(str, input().split()))
	front = s[0]
	back = s[1]
	left = s[2]
	right = s[3]
	top = s[4]
	down = s[5]
	if (front == left or front == right) and (front == top or front == down):
		print('YES')
	elif (back == left or back == right) and (back == top or back == down):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	s = input().split()
	(d, loc, p) = ({}, [], 0)
	for x in range(6):
		if s[x] in d:
			d[s[x]].append(x)
		else:
			d[s[x]] = [x]
	for i in d:
		if len(d[i]) >= 3:
			loc = d[i]
			break
	for l in range(0, 5, 2):
		if l in loc or l + 1 in loc:
			p += 1
	if p == 3:
		print('YES')
	else:
		print('NO')


pairwise = [[0, 2, 4], [0, 3, 4], [1, 3, 4], [1, 2, 4], [0, 2, 5], [0, 3, 5], [1, 3, 5], [1, 2, 5]]
for _ in range(int(input())):
	c = input().split()
	ans = 'NO'
	for i in pairwise:
		(x, y, z) = i
		if c[x] == c[y] == c[z]:
			ans = 'YES'
			break
	print(ans)


tests = int(input())
for i in range(tests):
	arr = list(input().split())
	ans = 'NO'
	if (arr[0] == arr[2] or arr[0] == arr[3]) and (arr[0] == arr[4] or arr[0] == arr[5]):
		ans = 'YES'
	elif (arr[1] == arr[2] or arr[1] == arr[3]) and (arr[1] == arr[4] or arr[1] == arr[5]):
		ans = 'YES'
	print(ans)


for _ in range(int(input())):
	a = input().split()
	y = 0
	if a[4] == a[0] == a[3]:
		y = 1
	elif a[4] == a[0] == a[2]:
		y = 1
	elif a[4] == a[1] == a[3]:
		y = 1
	elif a[4] == a[1] == a[2]:
		y = 1
	elif a[5] == a[0] == a[3]:
		y = 1
	elif a[5] == a[0] == a[2]:
		y = 1
	elif a[5] == a[1] == a[3]:
		y = 1
	elif a[5] == a[1] == a[2]:
		y = 1
	if y == 1:
		print('YES')
	else:
		print('NO')


import math
import sys

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

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

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

def _str():
	return sys.stdin.readline()

def _strarr():
	return sys.stdin.readline().split()

def adj(a, b, c):
	if b != opp[a] and b != opp[c] and (a != opp[c]):
		return True
	return False
t = _int()
opp = [1, 0, 3, 2, 5, 4]
for _ in range(t):
	c = _strarr()
	cd = dict()
	for i in range(len(opp)):
		ind = cd.get(c[i], [])
		ind.append(i)
		cd[c[i]] = ind
	found = False
	for k in list(cd.keys()):
		ind = cd.get(k, [])
		if len(ind) == 3:
			if adj(ind[0], ind[1], ind[2]):
				found = True
		elif len(ind) == 4:
			if adj(ind[0], ind[1], ind[2]):
				found = True
			elif adj(ind[0], ind[1], ind[3]):
				found = True
			elif adj(ind[0], ind[2], ind[3]):
				found = True
			elif adj(ind[1], ind[2], ind[3]):
				found = True
		elif len(ind) >= 5:
			found = True
		if found:
			break
	print('YES' if found else 'NO')


for t in range(int(input())):
	temp = list(input().split())
	front = temp[0]
	back = temp[1]
	left = temp[2]
	right = temp[3]
	top = temp[4]
	bottom = temp[5]
	if left == top and left == front:
		print('YES')
	elif left == top and left == back:
		print('YES')
	elif left == bottom and left == front:
		print('YES')
	elif left == bottom and left == back:
		print('YES')
	elif right == top and right == front:
		print('YES')
	elif right == top and right == back:
		print('YES')
	elif right == bottom and right == front:
		print('YES')
	elif right == bottom and right == back:
		print('YES')
	else:
		print('NO')


t = int(input())
for j in range(t):
	(f, ba, l, r, t, bo) = str(input()).split(' ')
	if l == f and f == bo:
		print('YES')
	elif l == f and l == t:
		print('YES')
	elif l == t and t == ba:
		print('YES')
	elif l == ba and ba == bo:
		print('YES')
	elif f == t and t == r:
		print('YES')
	elif t == ba and ba == r:
		print('YES')
	elif bo == r and r == f:
		print('YES')
	elif r == ba and ba == bo:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input().split()
	d = {}
	for i in range(6):
		try:
			d[s[i]].append(i)
		except:
			d[s[i]] = [i]
	flag = False
	for i in list(d.keys()):
		if len(d[i]) >= 3:
			if 0 in d[i] or 1 in d[i]:
				if (3 in d[i] or 2 in d[i]) and (4 in d[i] or 5 in d[i]):
					flag = True
					break
	if flag:
		print('YES')
	else:
		print('NO')


result = []
for _ in range(int(input())):
	(front, back, left, right, top, bottom) = input().split()
	if len(set([front, left, top])) == 1 or len(set([front, left, bottom])) == 1 or len(set([front, right, top])) == 1 or (len(set([front, right, bottom])) == 1) or (len(set([back, left, top])) == 1) or (len(set([back, left, bottom])) == 1) or (len(set([back, right, top])) == 1) or (len(set([back, right, bottom])) == 1):
		result.append('YES')
	else:
		result.append('NO')
for _ in result:
	print(_)


t = int(input())
while t:
	t -= 1
	s = input()
	(front, back, left, right, top, bottom) = s.split()
	if front == left and front == bottom and (left == bottom) or (front == right and front == bottom and (right == bottom)) or (front == left and front == top and (left == top)) or (front == right and front == top and (right == top)) or (back == left and back == bottom and (left == bottom)) or (back == right and back == bottom and (right == bottom)) or (back == left and back == top and (left == top)) or (back == right and back == top and (right == top)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = list(map(str, input().split()))
	a = [(1, 3, 5), (1, 3, 6), (1, 4, 5), (1, 4, 6), (2, 3, 5), (2, 3, 6), (2, 4, 5), (2, 4, 6)]
	c = 0
	for i in a:
		if len(set([l[i[0] - 1], l[i[1] - 1], l[i[2] - 1]])) == 1:
			c = 1
			break
	if c == 1:
		print('YES')
	else:
		print('NO')


def check(color):
	for f1 in [0, 1]:
		for f2 in [2, 3]:
			for f3 in [4, 5]:
				if color[f1] == color[f2] == color[f3]:
					return 'YES'
	return 'NO'
t = int(input())
while t > 0:
	colors = input().split()
	print(check(colors))
	t -= 1


dic = {'f': 0, 'ba': 0, 'l': 0, 'r': 0, 't': 0, 'bo': 0}
for _ in range(int(input())):
	x = input().split()
	for (i, j) in zip(dic, x):
		dic[i] = j[:3]
	if dic['t'] == dic['f'] == dic['r']:
		print('YES')
	elif dic['t'] == dic['f'] == dic['l']:
		print('YES')
	elif dic['t'] == dic['ba'] == dic['l']:
		print('YES')
	elif dic['t'] == dic['ba'] == dic['r']:
		print('YES')
	elif dic['bo'] == dic['f'] == dic['r']:
		print('YES')
	elif dic['bo'] == dic['f'] == dic['l']:
		print('YES')
	elif dic['bo'] == dic['ba'] == dic['l']:
		print('YES')
	elif dic['bo'] == dic['ba'] == dic['r']:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l = list(map(str, input().split()))
	(c, count) = (0, 0)
	if l[0] in l[2:4]:
		count += 1
	if l[0] in l[4:]:
		count += 1
	if l[1] in l[2:4]:
		c += 1
	if l[1] in l[4:]:
		c += 1
	if c == 2 or count == 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(f, b, l, r, t, d) = input().split()
	ans = False
	if (f == l or f == r) and (f == t or f == d):
		ans = True
	if (b == l or b == r) and (b == t or b == d):
		ans = True
	if (t == l or t == r) and (t == f or t == b):
		ans = True
	if (d == l or d == r) and (d == f or d == b):
		ans = True
	if (l == f or l == b) and (l == t or l == d):
		ans = True
	if (r == f or r == b) and (r == t or r == d):
		ans = True
	print('YES' if ans else 'NO')


for _ in range(int(input())):
	l = list(map(str, input().split()))
	(a, b) = (l[0], l[1])
	(i, s1, s2) = (2, 0, 0)
	while i < 6:
		if a in l[i:i + 2]:
			s1 += 1
		if b in l[i:i + 2]:
			s2 += 1
		i += 2
	if s1 > 1 or s2 > 1:
		print('YES')
	else:
		print('NO')


str = input()
T = int(str)
for ti in range(T):
	can = False
	str = input()
	S = str.split(' ')
	s = [[S[0], S[1]], [S[2], S[3]], [S[4], S[5]]]
	for x in (0, 1):
		for y in (0, 1):
			for z in (0, 1):
				if s[0][x] == s[1][y] == s[2][z]:
					can = True
	if can:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = list(input().split())
	s1 = []
	s2 = []
	s3 = []
	for i in range(6):
		if i <= 1:
			s1.append(l[i])
		elif i <= 3:
			s2.append(l[i])
		else:
			s3.append(l[i])
	colour = ['black', 'blue', 'red', 'green', 'yellow', 'orange']
	for i in colour:
		if i in s1 and i in s2 and (i in s3):
			print('YES')
			break
	else:
		print('NO')


indices = [[0, 2, 4], [0, 3, 4], [0, 2, 5], [0, 3, 5], [1, 2, 4], [1, 3, 4], [1, 2, 5], [1, 3, 5]]
for _ in range(int(input())):
	color = list(map(str, input().split()))
	ans = 'NO'
	for i in range(8):
		if color[indices[i][0]] == color[indices[i][1]] == color[indices[i][2]]:
			ans = 'YES'
			break
	print(ans)


t = int(input())
for i in range(t):
	l = list(map(str, input().strip().split()))
	k = max(set(l), key=l.count)
	p = l.count(k)
	if (l[0] == k or l[1] == k) and (l[2] == k or l[3] == k) and (l[4] == k or l[5] == k) and (p >= 3):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input().split(' ')
	flag = 0
	if s[0] == s[2]:
		if s[0] == s[4] or s[0] == s[5]:
			flag = 1
	if s[0] == s[3]:
		if s[0] == s[4] or s[0] == s[5]:
			flag = 1
	if s[1] == s[2]:
		if s[1] == s[4] or s[1] == s[5]:
			flag = 1
	if s[1] == s[3]:
		if s[1] == s[4] or s[1] == s[5]:
			flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


ujju = int(input())
for sai in range(ujju):
	u1 = list(map(str, input().split()))
	h = max(set(u1), key=u1.count)
	g = u1.count(h)
	if (u1[0] == h or u1[1] == h) and (u1[2] == h or u1[3] == h) and (u1[4] == h or u1[5] == h) and (g >= 3):
		print('YES')
	else:
		print('NO')


a = int(input(''))
for i in range(a):
	(F, Ba, L, R, T, B) = map(str, input('').split())
	if F == L == B or F == R == B or F == T == L or (F == T == R) or (Ba == L == B) or (Ba == R == B) or (Ba == T == L) or (Ba == T == R):
		print('YES')
	else:
		print('NO')


def get_answer(cube):
	if cube[0] in cube[2:4] and cube[0] in cube[4:len(cube)]:
		return 'YES'
	elif cube[1] in cube[2:4] and cube[1] in cube[4:len(cube)]:
		return 'YES'
	return 'NO'
test_case = int(input())
for i in range(0, test_case):
	cube = input().split(' ')
	print(get_answer(cube))


T = int(input())
while T > 0:
	a = list(map(str, input().split()))
	p = 0
	if a[5] == a[0] and a[5] == a[2]:
		p = 1
	if a[5] == a[2] and a[5] == a[1]:
		p = 1
	if a[5] == a[1] and a[5] == a[3]:
		p = 1
	if a[5] == a[0] and a[5] == a[3]:
		p = 1
	if a[4] == a[0] and a[4] == a[2]:
		p = 1
	if a[4] == a[2] and a[4] == a[1]:
		p = 1
	if a[4] == a[1] and a[4] == a[3]:
		p = 1
	if a[4] == a[0] and a[4] == a[3]:
		p = 1
	if p:
		print('YES')
	else:
		print('NO')
	T = T - 1


class Cube(object):

	def __init__(self, front, back, left, right, top, bottom):
		self.front = front
		self.back = back
		self.left = left
		self.right = right
		self.top = top
		self.bottom = bottom
T = int(input())
for _ in range(T):
	(front, back, left, right, top, bottom) = input().split()
	cube = Cube(front, back, left, right, top, bottom)
	del front, back, left, right, top, bottom
	cubePairs = [{cube.front, cube.back}, {cube.left, cube.right}, {cube.top, cube.bottom}]
	if len(cubePairs[0] & cubePairs[1] & cubePairs[2]) > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(f, b, l, r, t, bt) = [str(i) for i in input().split()]
	if (f == l or f == r) and (f == t or f == bt) or ((b == l or b == r) and (b == t or b == bt)):
		print('YES')
	else:
		print('NO')


import collections
for _ in range(int(input())):
	(f, ba, l, r, t, b) = [x for x in input().split()]
	if l == f == b or l == f == t or l == ba == b or (l == ba == t) or (r == f == b) or (r == f == t) or (r == ba == b) or (r == ba == t):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = list(map(str, input().split()))
	if s[0] == s[3] == s[-1] or s[0] == s[3] == s[-2] or s[0] == s[2] == s[-1] or (s[0] == s[2] == s[-2]):
		print('YES')
	elif s[1] == s[3] == s[-1] or s[1] == s[3] == s[-2] or s[1] == s[2] == s[-1] or (s[1] == s[2] == s[-2]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(front, back, left, right, top, bottom) = map(str, input().split())
	ans = 'NO'
	if (front == left or front == right) and (front == top or front == bottom):
		ans = 'YES'
	elif (back == left or back == right) and (back == top or back == bottom):
		ans = 'YES'
	print(ans)


T = int(input())
for t in range(T):
	color = input().split()
	s1 = color[:2]
	s2 = color[2:4]
	s3 = color[4:6]
	bo = False
	for i in range(2):
		for j in range(2):
			for k in range(2):
				if s1[i] == s2[j] == s3[k]:
					bo = True
	if bo:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = input().split()
	if (a == c or a == d) and (a == e or a == f):
		print('YES')
	elif (b == c or b == d) and (b == e or b == f):
		print('YES')
	else:
		print('NO')


l = [[0, 4, 2], [0, 4, 3], [0, 5, 2], [0, 5, 3], [1, 4, 2], [1, 4, 3], [1, 5, 2], [1, 5, 3]]

def check():
	inp = input().split(' ')
	for [i, j, k] in l:
		if inp[i] == inp[j] and inp[j] == inp[k]:
			return 'YES'
	return 'NO'

def main():
	t = int(input())
	while t > 0:
		print(check())
		t -= 1
	return
main()


list_triplets = [('front', 'left', 'top'), ('top', 'left', 'back'), ('top', 'right', 'back'), ('front', 'right', 'top'), ('front', 'left', 'bottom'), ('bottom', 'left', 'back'), ('bottom', 'right', 'back'), ('front', 'right', 'bottom')]
input_order = ['front', 'back', 'left', 'right', 'top', 'bottom']
n = input()
for _ in range(int(n)):
	colors = input()
	colors = colors.split()
	color_map = {side: color for (side, color) in zip(input_order, colors)}
	flag = False
	for triplet in list_triplets:
		current_color = None
		triplet_flag = True
		for side in triplet:
			if current_color is None:
				current_color = color_map.get(side)
			if current_color != color_map.get(side):
				triplet_flag = False
		if triplet_flag is True:
			flag = True
	if flag is True:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	l = input().split()
	c = 0
	c1 = 0
	if l[0] in l[2:4]:
		c1 += 1
	if l[0] in l[4:]:
		c1 += 1
	if l[1] in l[2:4]:
		c += 1
	if l[1] in l[4:]:
		c += 1
	print('YES' if c == 2 or c1 == 2 else 'NO')


T = int(input())
ii = 0
while ii < T:
	sides = str(input())
	sides = sides.split()
	dice = {}
	corners = [[0, 4, 3], [0, 3, 5], [0, 5, 2], [0, 2, 4], [1, 4, 3], [1, 3, 5], [1, 5, 2], [1, 2, 4]]
	flag = 0
	i = 0
	while i < 8:
		trip = corners[i]
		if sides[corners[i][0]] == sides[corners[i][1]] and sides[corners[i][0]] == sides[corners[i][2]]:
			flag = 1
			break
		else:
			i += 1
	if flag:
		print('YES')
	else:
		print('NO')
	ii += 1


for _ in range(int(input())):
	(front, back, left, right, top, bottom) = input().split()
	if front == left == top or front == left == bottom or front == right == top or (front == right == bottom) or (back == left == top) or (back == left == bottom) or (back == right == top) or (back == right == bottom):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	c = list(map(str, input().split()))
	if c[0] == c[2] == c[5] or c[0] == c[5] == c[3] or c[5] == c[3] == c[1] or (c[5] == c[1] == c[2]) or (c[0] == c[2] == c[4]) or (c[0] == c[4] == c[3]) or (c[4] == c[3] == c[1]) or (c[4] == c[1] == c[2]):
		print('YES')
	else:
		print('NO')


T = int(input())
while T > 0:
	a = list(map(str, input().split()))
	p = 0
	for i in range(4, 6):
		if a[i] == a[0] and a[i] == a[2]:
			p = 1
		elif a[i] == a[2] and a[i] == a[1]:
			p = 1
		elif a[i] == a[1] and a[i] == a[3]:
			p = 1
		elif a[i] == a[0] and a[i] == a[3]:
			p = 1
	if p:
		print('YES')
	else:
		print('NO')
	T = T - 1


import math
t = int(input())
while t >= 1:
	a = input()
	a = a.split()
	y = 0
	if a[4] == a[0] == a[3]:
		y = 1
	elif a[4] == a[0] == a[2]:
		y = 1
	elif a[4] == a[1] == a[3]:
		y = 1
	elif a[4] == a[1] == a[2]:
		y = 1
	elif a[5] == a[0] == a[3]:
		y = 1
	elif a[5] == a[0] == a[2]:
		y = 1
	elif a[5] == a[1] == a[3]:
		y = 1
	elif a[5] == a[1] == a[2]:
		y = 1
	if y == 1:
		print('YES')
	else:
		print('NO')
	t = t - 1


base = ((0, 2), (0, 3), (1, 2), (1, 3))
for _ in range(int(input())):
	c = list(input().split())
	ans = 'NO'
	for b in base:
		if c[b[0]] == c[b[1]]:
			if c[b[0]] == c[4] or c[b[0]] == c[5]:
				ans = 'YES'
				break
	print(ans)


def buildTriples():
	triples = [[] for _ in range(8)]
	triples[0] = [0, 2, 4]
	triples[1] = [1, 2, 4]
	triples[2] = [1, 3, 4]
	triples[3] = [0, 3, 4]
	triples[4] = [0, 2, 5]
	triples[5] = [1, 2, 5]
	triples[6] = [1, 3, 5]
	triples[7] = [0, 3, 5]
	return triples

def solve(triples, a):
	for t in triples:
		if a[t[0]] == a[t[1]] == a[t[2]]:
			return 'YES'
	return 'NO'
T = int(input())
triples = buildTriples()
for _ in range(T):
	print(solve(triples, input().split()))


from collections import Counter
t = int(input())
flag = 0
for i in range(1, t + 1):
	flag = 0
	a = input().split()
	b = Counter(a)
	for color in ['black', 'blue', 'red', 'green', 'yellow', 'orange']:
		if b[color] >= 3:
			if (a[0] == color or a[1] == color) and (a[2] == color or a[3] == color) and (a[4] == color or a[5] == color):
				print('YES')
				flag = 1
				break
	if flag == 0:
		print('NO')


for _ in range(int(input())):
	(f, ba, l, r, t, bo) = input().split()
	if (f == l or f == r) and (f == t or f == bo) or ((ba == l or ba == r) and (ba == t or ba == bo)):
		print('YES')
	else:
		print('NO')


color_list = ['black', 'blue', 'red', 'green', 'yellow', 'orange']
for _ in range(int(input())):
	ans = 'NO'
	painted = input().split()
	(fb, lr, tb) = (painted[:2], painted[2:4], painted[4:6])
	for i in color_list:
		if i in fb and i in lr and (i in tb):
			ans = 'YES'
			break
	print(ans)


T = int(input())
for i in range(0, T):
	(f, b, l, r, t, bo) = map(str, input().split())
	if (f == l or f == r) and (f == t or f == bo):
		print('YES')
	elif (b == l or b == r) and (b == t or b == bo):
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	s = input().split()
	a = 0
	if s[0] == s[2] == s[4]:
		a = 1
	elif s[0] == s[3] == s[4]:
		a = 1
	elif s[0] == s[3] == s[5]:
		a = 1
	elif s[0] == s[2] == s[5]:
		a = 1
	elif s[1] == s[3] == s[4]:
		a = 1
	elif s[1] == s[2] == s[4]:
		a = 1
	elif s[1] == s[3] == s[5]:
		a = 1
	elif s[1] == s[2] == s[5]:
		a = 1
	if a == 1:
		print('YES')
	else:
		print('NO')
	t = t - 1


def check(s1, s2, s3):
	if s1 == s2 and s2 == s3 and (s3 == s1):
		return True
	else:
		return False
for _ in range(int(input())):
	(f, b, l, r, t, bo) = input().split()
	if check(f, t, l) or check(f, t, r) or check(f, bo, l) or check(f, bo, r) or check(b, t, l) or check(b, t, r) or check(b, bo, l) or check(b, bo, r):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	List = [str(x) for x in input().split()]
	if List[0] == List[3] == List[4] or List[0] == List[3] == List[5] or List[0] == List[2] == List[4] or (List[0] == List[2] == List[5]) or (List[1] == List[3] == List[4]) or (List[1] == List[3] == List[5]) or (List[1] == List[2] == List[4]) or (List[1] == List[2] == List[5]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	arr = list(map(str, input().split()))
	(front, back, left, right, top, bottom) = arr
	if front == right == bottom or front == right == top or front == left == bottom or (front == left == top):
		print('YES')
	elif back == left == top or front == left == top or top == front == right or (right == back == top):
		print('YES')
	elif right == back == top or right == front == top or bottom == front == right or (right == back == bottom):
		print('YES')
	elif bottom == front == right or bottom == left == front or bottom == back == left or (bottom == back == right):
		print('YES')
	elif left == back == top or bottom == left == back or bottom == front == left or (left == front == top):
		print('YES')
	elif back == top == right or back == left == top or bottom == back == left or (bottom == back == right):
		print('YES')
	else:
		print('NO')


t = int(input())
for ni in range(t):
	s = input().split()
	(f, b) = (s[0], s[1])
	l1 = [s[2], s[3]]
	l2 = [s[4], s[5]]
	if f in l1 and f in l2:
		print('YES')
	elif b in l1 and b in l2:
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	(f, b, l, r, t, d) = map(str, input().split())
	if t == f and t == l or (t == f and t == r):
		print('YES')
	elif f == d and d == l or (f == d and d == r):
		print('YES')
	elif b == d and d == l or (b == d and d == r):
		print('YES')
	elif b == t and t == r or (b == t and t == l):
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	l = list(map(str, input().split()))
	L = [[0, 2, 4], [0, 3, 4], [0, 2, 5], [0, 3, 5], [1, 2, 4], [1, 3, 4], [1, 2, 5], [1, 3, 5]]
	f = 1
	for i in range(8):
		l1 = L[i]
		if l[l1[0]] == l[l1[1]] and l[l1[0]] == l[l1[2]]:
			print('YES')
			f = 0
			break
	if f == 1:
		print('NO')


for _ in range(int(input())):
	l = list(map(str, input().split()))
	if l[0] == l[2] and l[2] == l[5] or (l[0] == l[2] and l[2] == l[4]) or (l[0] == l[3] and l[3] == l[5]) or (l[0] == l[3] and l[3] == l[4]) or (l[1] == l[2] and l[2] == l[5]) or (l[1] == l[2] and l[2] == l[4]) or (l[1] == l[3] and l[3] == l[5]) or (l[1] == l[3] and l[3] == l[4]):
		print('YES')
	else:
		print('NO')


t = input()
for c in range(0, int(t)):
	arr = list(input().split())
	ans = 'NO'
	if (arr[0] == arr[2] or arr[0] == arr[3]) and (arr[0] == arr[4] or arr[0] == arr[5]):
		ans = 'YES'
	elif (arr[1] == arr[2] or arr[1] == arr[3]) and (arr[1] == arr[4] or arr[1] == arr[5]):
		ans = 'YES'
	print(ans)


t = int(input())
for i in range(t):
	(col1, col2, col3, col4, col5, col6) = input().split()
	if set([col1, col2]) & set([col3, col4]) & set([col5, col6]):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	C = input().split()
	if C[0] == C[2] == C[4] or C[0] == C[2] == C[5] or C[0] == C[3] == C[4] or (C[0] == C[3] == C[5]) or (C[1] == C[2] == C[4]) or (C[1] == C[2] == C[5]) or (C[1] == C[3] == C[4]) or (C[1] == C[3] == C[5]):
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	(front, back, left, right, top, bottom) = input().split()
	possible = {'black', 'blue', 'red', 'green', 'yellow', 'orange'}
	ans = 'NO'
	(f1, f2, b1, b2) = (False, False, False, False)
	if front in (left, right):
		f1 = True
	if front in (top, bottom):
		f2 = True
	if back in (left, right):
		b1 = True
	if back in (top, bottom):
		b2 = True
	if f1 and f2:
		ans = 'YES'
	if b1 and b2:
		ans = 'YES'
	print(ans)


from collections import *
for u in range(int(input())):
	l = input().split()
	C = l
	if C[0] == C[2] == C[4] or C[0] == C[2] == C[5] or C[0] == C[3] == C[4] or (C[0] == C[3] == C[5]) or (C[1] == C[2] == C[4]) or (C[1] == C[2] == C[5]) or (C[1] == C[3] == C[4]) or (C[1] == C[3] == C[5]):
		print('YES')
	else:
		print('NO')


listk = []
for _ in range(int(input())):
	cc = input().split()
	cc1 = set(cc[0:2])
	cc2 = set(cc[2:4])
	cc3 = set(cc[4:])
	if cc1.intersection(cc2.intersection(cc3)) != set():
		listk.append('YES')
	else:
		listk.append('NO')
for ele in listk:
	print(ele)