Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef knows about two languages spoken in Chefland, but he is not proficient in any of them. The first language contains lowercase English letters between 'a' and 'm' inclusive and the second language contains only uppercase English letters between 'N' and 'Z' inclusive.

Due to Chef's limited vocabulary, he sometimes mixes the languages when forming a sentence — each word of Chef's sentence contains only characters from one of the languages, but different words may come from different languages.

You are given a sentence as a sequence of $K$ words $S_{1}, S_{2}, \ldots, S_{K}$. Determine whether it could be a sentence formed by Chef, i.e. if it contains only the characters from the two given languages and each word contains only characters from a single language.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains an integer $K$ followed by a space and $K$ space-separated strings $S_{1}, S_{2}, \ldots, S_{K}$. 

------  Output ------
For each test case, print a single line containing the string "YES" if the given sentence can be formed by Chef or "NO" if it cannot.

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ K ≤ 10$
$1 ≤ |S_{i}| ≤ 100$ for each valid $i$
the sum of lengths of all the strings on the input does not exceed $10^{5}$
each string contains only lowercase and uppercase English letters

----- Sample Input 1 ------ 
3

1 aN

2 ab NO

3 A N D
----- Sample Output 1 ------ 
NO

YES

NO
----- explanation 1 ------ 
Example case 1: A single word cannot contain characters from both languages.

Example case 2: This could be a sentence formed by Chef since each word contains only characters from a single language.

Example case 3: Letters 'A' and 'D' do not belong to either of the two languages.

Difficulty: MEDIUM
Tags: String algorithms

Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
for i in range(int(input())):
	arr = list(input().split())
	list1 = list('abcdefghijklm')
	list2 = list('NOPQRSTUVWXYZ')
	for i in range(1, len(arr)):
		list3 = list(arr[i])
		ch = list3[0]
		x = len(list3)
		if x >= 2:
			if ch in list1:
				for j in range(1, x):
					if list3[j] in list1:
						continue
				if list3[j] not in list1:
					print('NO')
					break
			elif ch not in list1 and ch not in list2:
				print('NO')
				break
			if ch in list2:
				for k in range(1, x):
					if list3[k] in list2:
						continue
				if list3[k] not in list2:
					print('NO')
					break
			elif ch not in list2 and ch not in list1:
				print('NO')
				break
		elif x < 2:
			if ch in list1 or ch in list2:
				pass
			elif ch not in list1 and ch not in list2:
				print('NO')
				break
		if i == len(arr) - 1:
			print('YES')


t = int(input())
s1 = 'abcdefghijklm'
s2 = 'NOPQRSTUVWXYZ'
s3 = 'JSG7GJJHDSKJ'
for i in range(0, t):
	f = input().split(' ')
	sum = 0
	for k in range(1, int(f[0]) + 1):
		ll = f[k].lower()
		uu = f[k].upper()
		if f[k] == ll:
			for j in f[k]:
				if j not in s1:
					sum = 1
		elif f[k] == uu:
			for j in f[k]:
				if j not in s2:
					sum = 1
		else:
			sum = 1
		if sum == 1:
			print('NO')
			break
	if sum == 0:
		print('YES')


l1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
l2 = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for _ in range(int(input())):
	s = input().split()
	c = int(s[0])
	d = e = f = ans = 0
	a = s[1:]
	for i in range(len(a)):
		d = e = 0
		for j in range(len(a[i])):
			t = a[i]
			if t[j] in l1:
				d += 1
			elif t[j] in l2:
				e += 1
		if len(a[i]) == d or len(a[i]) == e:
			ans += 1
	if ans == c:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	b = list(input().split(' '))
	aws = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
	asw = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	s = True
	for i in range(1, len(b)):
		if len(b[i]) > 1:
			for j in range(len(b[i]) - 1):
				if b[i][j] in aws and b[i][j + 1] in aws or (b[i][j] in asw and b[i][j + 1] in asw):
					continue
				else:
					s = False
		elif b[i] in aws or b[i] in asw:
			continue
		else:
			s = False
	if s == True:
		print('YES')
	else:
		print('NO')


a = [chr(i) for i in range(97, 110)]
b = [chr(i) for i in range(78, 91)]
for i in range(int(input())):
	s = input().split(' ')
	l = list(s)
	c = l[1:]
	g = 0
	h = 0
	for i in range(len(c)):
		e = 0
		f = 0
		for j in range(len(c[i])):
			d = c[i]
			if d[j] in a:
				e += 1
			elif d[j] in b:
				f += 1
		if len(c[i]) == e or len(c[i]) == f:
			g += 1
		else:
			h += 1
	if g == len(c):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	inp = input()
	ls = inp.split(' ')
	flag = 0
	for k in range(1, int(ls[0]) + 1):
		if ord(ls[k][0]) < 91:
			(x, y) = (78, 91)
		else:
			(x, y) = (97, 110)
		if not all((ord(j) in range(x, y) for j in ls[k])):
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	xxx = list(map(str, input().split()))
	f = True
	x = 'abcdefghijklm'
	xx = 'NOPQRSTUVWXYZ'
	for i in xxx[1:]:
		if i[0] in x:
			for j in i:
				if j not in x:
					f = False
					break
		elif i[0] in xx:
			for j in i:
				if j not in xx:
					f = False
					break
		else:
			f = False
			break
	print('YES' if f else 'NO')


t = int(input())
while t > 0:
	l = list(input().split())
	s = len(l)
	j = 1
	f3 = 1
	while j < s:
		f1 = 0
		f2 = 0
		o = len(l[j])
		p = 0
		while p < o:
			if 109 >= ord(l[j][p]) >= 97:
				f1 = 1
			elif 90 >= ord(l[j][p]) >= 78:
				f2 = 1
			else:
				f3 = 0
				break
			p += 1
		if f3 == 0:
			break
		if f1 == 1 and f2 == 1:
			f3 = 0
			break
		j += 1
	if f3 == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	kands = input()
	kands = kands.split()
	k = int(kands[0])
	s = [kands[i] for i in range(1, len(kands))]
	first = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
	second = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	flag = 0
	for i in s:
		f = 0
		sec = 0
		for j in i:
			if j in first:
				f += 1
			elif j in second:
				sec += 1
			else:
				flag = 1
				break
		if f == len(i) or sec == len(i):
			pass
		else:
			flag = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

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

def insr():
	return input().strip()

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
ans = []
for _ in range(inp()):
	an = 'NO'
	for s in input().split()[1:]:
		if not (s.islower() and max(s) <= 'm' or (s.isupper() and min(s) >= 'N')):
			break
	else:
		an = 'YES'
	ans.append(an)
outplt(ans)


import sys
input = sys.stdin.readline

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

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

def insr():
	return input().strip()

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
(a, m, N, Z) = [ord(x) for x in 'amNZ']
ans = []

def test(x):
	o = ord(x)
	if not (a <= o <= m or N <= o <= Z):
		return 0
	return 1 if o < a else 2
for _ in range(inp()):
	S = input().split()[1:]
	an = 'NO'
	for s in S:
		x = test(s[0])
		if not x:
			break
		for ss in s:
			if x != test(ss):
				break
		else:
			continue
		break
	else:
		an = 'YES'
	ans.append(an)
outplt(ans)


t = int(input())
for i in range(t):
	s = input()
	n = int(s[0])
	lst = list(s[2:].split(' '))
	flag = True
	for i in s:
		if i.isalpha():
			if i >= 'a' and i <= 'm' or (i >= 'N' and i <= 'Z'):
				pass
			else:
				flag = False
				break
	if flag == False:
		print('NO')
	else:
		for i in lst:
			if i.islower() == True or i.isupper() == True:
				pass
			else:
				flag = False
				break
		if flag == False:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	l = [i for i in input().split()]
	k = int(l[0])
	z = 0
	lan1 = 'abcdefghijklm'
	lan2 = 'NOPQRSTUVWXYZ'
	for i in range(1, k + 1):
		if l[i].islower():
			for j in l[i]:
				if j not in lan1:
					z = 1
					break
		elif l[i].isupper():
			for n in l[i]:
				if n not in lan2:
					z = 1
					break
		else:
			z = 1
		if z == 1:
			print('NO')
			break
	if z == 0:
		print('YES')


for _ in range(int(input())):
	a = list(map(str, input().split()))
	f1 = True
	for i in range(1, int(a[0]) + 1):
		if a[i][0] <= 'm' and a[i][0] >= 'a':
			f = True
		elif a[i][0] >= 'N' and a[i][0] <= 'Z':
			f = False
		else:
			f1 = False
			break
		if f:
			n1 = 'a'
			n2 = 'm'
		else:
			n1 = 'N'
			n2 = 'Z'
		for j in a[i]:
			if j >= n1 and j <= n2:
				continue
			else:
				f1 = False
				break
	if f1:
		print('YES')
	else:
		print('NO')


xx = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
yy = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for x in range(int(input())):
	a = [str(d) for d in input().split()]
	n = int(a[0])
	a = a[1:]
	final = 0
	for char in a:
		cc = 0
		dd = 0
		total = 0
		for x in char:
			if x in xx:
				cc += 1
			elif x in yy:
				dd += 1
		if cc == len(char):
			final += 1
		elif dd == len(char):
			final += 1
		else:
			break
	if final == len(a):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = input().split()
	del a[0]
	for k in a:
		val = 0
		if ord(k[0]) >= 97 and ord(k[0]) <= 109:
			for q in k:
				if ord(q) >= 97 and ord(q) <= 109:
					val = 1
				else:
					val = 0
					break
			if val == 0:
				break
		elif ord(k[0]) >= 78 and ord(k[0]) <= 90:
			for q in k:
				if ord(q) >= 78 and ord(q) <= 90:
					val = 1
				else:
					val = 0
					break
			if val == 0:
				break
		else:
			val = 0
			break
	if val == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	a = [i for i in input().split()]
	k = int(a[0])
	s = a[1:]

	def f() -> bool:
		for i in range(k):
			n1 = 0
			n2 = 0
			flag1 = 0
			flag2 = 0
			for j in range(len(s[i])):
				if s[i][j].islower() and ord(s[i][j]) - 97 <= 12:
					n1 += 1
				elif s[i][j].islower() and ord(s[i][j]) - 97 > 12:
					flag1 = 1
				elif s[i][j].isupper() and ord(s[i][j]) - 65 >= 13:
					n2 += 1
				elif s[i][j].isupper() and ord(s[i][j]) - 65 < 13:
					flag2 = 1
			if n1 >= 1 and n2 >= 1:
				return False
			elif flag1 == 1 or flag2 == 1:
				return False
		return True
	if f() == True:
		print('YES')
	else:
		print('NO')
	t -= 1


lang1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
lang2 = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for _ in range(int(input())):
	sent = []
	(k, *sent) = input().split(' ')
	k = int(k)
	for i in range(k):
		word = sent[i]
		lang = 0
		for j in word:
			if j in lang1 and (lang == 0 or lang == 1):
				lang = 1
			elif j in lang2 and (lang == 0 or lang == 2):
				lang = 2
			else:
				lang = -1
		if lang == -1:
			break
	if lang == -1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	sentence = input().split()
	res = 'YES'
	del sentence[0]
	for word in sentence:
		if ord(word[0]) in range(97, 110):
			range_var = range(97, 100)
			for i in word:
				if ord(i) not in range(97, 110):
					res = 'NO'
		else:
			for i in word:
				if ord(i) not in range(78, 91):
					res = 'NO'
	print(res)


tests = int(input())
for i in range(tests):
	(length, *arr) = input().split()
	ans = 'YES'
	for j in arr:
		if j.lower() == j:
			if not 'a' <= min(j) <= 'm' or not 'a' <= max(j) <= 'm':
				ans = 'NO'
		elif j.upper() == j:
			if not 'N' <= min(j) <= 'Z' or not 'N' <= max(j) <= 'Z':
				ans = 'NO'
		else:
			ans = 'NO'
		if ans == 'NO':
			break
	print(ans)


tests = int(input())
for i in range(tests):
	(length, *arr) = input().split()
	ans = 'YES'
	for j in arr:
		if j.lower() == j:
			if not 97 <= ord(max(j)) <= 109 or not 97 <= ord(min(j)) <= 109:
				ans = 'NO'
		elif j.upper() == j:
			if not 78 <= ord(max(j)) <= 90 or not 78 <= ord(min(j)) <= 90:
				ans = 'NO'
		else:
			ans = 'NO'
		if ans == 'NO':
			break
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	s = s.split()
	l = 1
	for i in range(1, len(s)):
		if s[i][0] >= 'a' and s[i][0] <= 'm':
			for j in range(1, len(s[i])):
				if s[i][j] >= 'a' and s[i][j] <= 'm':
					continue
				else:
					l = 0
					break
		elif s[i][0] >= 'N' and s[i][0] <= 'Z':
			for j in range(1, len(s[i])):
				if s[i][j] >= 'N' and s[i][j] <= 'Z':
					continue
				else:
					l = 0
					break
		else:
			l = 0
		if l == 0:
			break
	if l == 1:
		print('YES')
	else:
		print('NO')


l1 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'}
l2 = {'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
n = int(input())
for i in range(0, n):
	a = input().split()
	a[0] = int(a[0])
	valid = True
	for j in range(1, a[0] + 1):
		b = set(list(a[j]))
		if b <= l1 or b <= l2:
			pass
		else:
			valid = False
			break
	if valid:
		print('YES')
	else:
		print('NO')


x = int(input())
for i in range(x):
	t = 0
	y = list(input().split())
	for j in range(1, len(y)):
		s = 0
		r = 0
		if y[j].islower():
			for k in range(len(y[j])):
				if ord(y[j][k]) >= 97 and ord(y[j][k]) <= 109:
					s = s + 1
		else:
			for k in range(len(y[j])):
				if ord(y[j][k]) >= 78 and ord(y[j][k]) <= 90:
					r = r + 1
		if s == len(y[j]) or r == len(y[j]):
			t = t + 1
	if t == len(y) - 1:
		print('YES')
	else:
		print('NO')


def lang1(word):
	for i in word:
		if not (i >= 'a' and i <= 'm'):
			return False
	return True

def lang2(word):
	for i in word:
		if not (i >= 'N' and i <= 'Z'):
			return False
	return True
for _ in range(int(input())):
	lst = input().split()
	k = int(lst[0])
	check = True
	i = 1
	while i <= k:
		if not (lang1(lst[i]) or lang2(lst[i])):
			check = False
			break
		i += 1
	if check:
		print('YES')
	else:
		print('NO')


l1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
l2 = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
t = int(input())
for _ in range(t):
	l = input().split()
	n = int(l[0])
	del l[0]
	for i in range(n):
		z = 0
		cn = 0
		for j in range(len(l[i])):
			if l[i][j] in l1:
				if j != 0:
					cn1 = 1
					if cn1 != cn:
						z = 1
						break
				else:
					cn = 1
			elif l[i][j] in l2:
				if j != 0:
					cn1 = 2
					if cn1 != cn:
						z = 1
						break
				else:
					cn = 2
			else:
				z = 1
				break
		if z == 1:
			print('NO')
			break
	if z == 0:
		print('YES')


def func():
	arr = input().split()
	k = int(arr[0])
	l1 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'}
	l2 = {'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
	ln1 = 0
	ln2 = 0
	for i in range(1, k + 1):
		ln1 = 0
		ln2 = 0
		for j in arr[i]:
			if str(j) in l1:
				ln1 = 1
			elif str(j) in l2:
				ln2 = 1
			else:
				return 0
		if ln1 == 1 and ln2 == 1:
			return 0
	return 1
t = int(input())
while t:
	if func() == 0:
		print('NO')
	else:
		print('YES')
	t -= 1


import re
pattern1 = '[^a-m]'
pattern2 = '[^N-Z]'
t = int(input())
while t > 0:
	str = input().split()
	count = 0
	for i in str:
		if not re.search(pattern1, i):
			count = count + 1
		elif not re.search(pattern2, i):
			count = count + 1
	if count == len(str) - 1:
		print('YES')
	else:
		print('NO')
	t = t - 1


from math import gcd, sqrt, ceil, floor, log10
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
import sys
import time
import string
import operator
sys.setrecursionlimit(3000000)
INT_MAX = float('inf')
INT_MIN = float('-inf')
MOD = int(1000000000.0) + 7
NEWLINE = '\n'
SPACE = ' '
inp = lambda fn: fn(input())
inp_vars = lambda fn, delim, convert_to=list: convert_to(map(fn, input().split(delim)))

def solve(*args, **kwargs):
	(n, *words) = args[0]
	(first, second) = (string.ascii_lowercase[:13], string.ascii_lowercase[13:].upper())
	cnt = 0
	for w in words:
		cnt += all((ch in first for ch in w)) or all((ch in second for ch in w))
	return 'YES' if cnt == int(n) else 'NO'

def main(*args, **kwargs):
	for _ in range(int(input())):
		arg2 = inp_vars(str, SPACE)
		res = solve(*(arg2,))
		if type(res) in {list, tuple, set}:
			print(*res, sep=' ')
		else:
			print(res)
main()


for _ in range(int(input())):
	temp = list(input().split(' '))
	n = int(temp.pop(0))
	ans = True
	for i in range(len(temp)):
		if temp[i][0] >= 'a' and temp[i][0] <= 'm':
			group = 1
		elif temp[i][0] >= 'N' and temp[i][0] <= 'Z':
			group = 2
		else:
			ans = False
			break
		for j in temp[i]:
			if group == 1:
				if not (j >= 'a' and j <= 'm'):
					ans = False
			if group == 2:
				if not (j >= 'N' and j <= 'Z'):
					ans = False
		if ans == False:
			break
	if ans == False:
		print('NO')
	else:
		print('YES')


list1 = [chr(i) for i in range(97, 110)]
list2 = [chr(i) for i in range(78, 91)]
for _ in range(int(input())):
	words = list(map(str, input().split()))[1:]
	flag = 0
	for i in range(len(words)):
		temp = words[i][0]
		if temp in list1:
			for j in words[i]:
				if j not in list1:
					print('NO')
					flag = 1
					break
		else:
			for j in words[i]:
				if j not in list2:
					print('NO')
					flag = 1
					break
		if flag == 1:
			break
	if flag == 0:
		print('YES')


for i in range(int(input())):
	arr = [i for i in input().split()]
	n = int(arr[0])
	arr = arr[1:]
	flag = False
	for i in arr:
		if i != i.lower() and i != i.upper():
			flag = True
			break
		elif i == i.lower():
			for j in i:
				if j > 'm':
					flag = True
					break
			if flag:
				break
		else:
			for j in i:
				if j < 'N':
					flag = True
					break
				if flag:
					break
	if flag:
		print('NO')
	else:
		print('YES')


from sys import stdin
L1 = 'abcdefghijklm'
L2 = 'NOPQRSTUVWXYZ'
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip().split()
	r = True
	for si in s[1:]:
		q1 = all((x in L1 for x in si))
		q2 = all((x in L2 for x in si))
		if q1 == q2:
			r = False
			break
	print('YES' if r else 'NO')


def answer(l):
	l = l.split()
	for i in l:
		if i.lower() == i:
			for chara in i:
				if 97 <= ord(chara) <= 109:
					pass
				else:
					return 'NO'
		elif i.upper() == i:
			for chara in i:
				if 78 <= ord(chara) <= 90:
					pass
				else:
					return 'NO'
		else:
			return 'NO'
	return 'YES'
for q in range(int(input())):
	a = input()[2:]
	print(answer(a))


t = int(input())
for i in range(t):
	l = list(map(str, input().split()))
	l.pop(0)
	f = ''
	for i in l:
		(l1, l2) = (0, 0)
		flag = ''
		for j in i:
			if ord(j) in range(97, 110):
				l1 += 1
			if ord(j) in range(78, 91):
				l2 += 1
			if l1 != 0 and l2 != 0:
				flag = 'fail'
				break
			if ord(j) not in range(97, 110) and ord(j) not in range(78, 91):
				flag = 'fail'
				break
		if flag == 'fail':
			print('NO')
			f = 'fail'
			break
	if f == '':
		print('YES')


for _ in range(int(input())):
	a = list(map(str, input().split()))
	b = []
	c = []
	ans = 0
	k = int(a[0])
	a.remove(a[0])
	for i in range(97, 110):
		b.append(chr(i))
	for i in range(78, 91):
		c.append(chr(i))
	for i in range(k):
		if a[i].isupper():
			var = list(a[i])
			if all((item in c for item in var)):
				ans = 1
			else:
				ans = 0
				break
		elif a[i].islower():
			var = list(a[i])
			if all((item in b for item in var)):
				ans = 1
			else:
				ans = 0
				break
		else:
			ans = 0
			break
	if ans == 1:
		print('YES')
	else:
		print('NO')


def check(array):
	for i in range(1, array[0] + 1):
		if ord(array[i][0]) >= 97 and ord(array[i][0]) <= 109:
			x = 1
		elif ord(array[i][0]) >= 78 and ord(array[i][0]) <= 90:
			x = 2
		else:
			print('NO')
			return
		for j in array[i]:
			if x == 1 and (ord(j) < 97 or ord(j) > 109):
				print('NO')
				return
			elif x == 2 and (ord(j) < 78 or ord(j) > 90):
				print('NO')
				return
			else:
				continue
	print('YES')
	return
for _ in range(int(input())):
	array = input().split()
	array[0] = int(array[0])
	check(array)


t = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'i', 'k', 'l', 'm']
b = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(t):
	n = list(map(str, input().split(' ')))
	c = []
	for i in range(int(n[0])):
		d = n[i + 1]
		c.append(list(d))
	y = 0
	for i in c:
		if all((x in a for x in i)):
			y += 1
		elif all((x in b for x in i)):
			y += 1
		else:
			y -= 1
	if y == len(c):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	li = input().split()
	li = li[1:]
	ans = 'YES'
	for i in range(len(li)):
		w = li[i]
		l = 0
		u = 0
		for c in w:
			if c.islower() and 'a' <= c <= 'm':
				l += 1
			if c.isupper() and 'N' <= c <= 'Z':
				u += 1
		if l != len(w) and u != len(w):
			ans = 'NO'
			break
	print(ans)


T = int(input())
for i in range(T):
	s = list(map(str, input().split()))
	s.pop(0)
	Fail = False
	for j in s:
		s1 = 0
		s2 = 0
		Flag = False
		for k in j:
			if ord(k) in range(97, 110):
				s1 += 1
			if ord(k) in range(78, 91):
				s2 += 1
			if s1 != 0 and s2 != 0:
				Flag = True
				break
			if ord(k) not in range(97, 110) and ord(k) not in range(78, 91):
				Flag = True
				break
		if Flag == True:
			print('NO')
			Fail = True
			break
	if Fail == False:
		print('YES')


t = int(input())
for _ in range(t):
	s = list(map(str, input().split()))
	s.pop(0)
	fail = False
	for i in s:
		(s1, s2) = (0, 0)
		flag = False
		for j in i:
			if ord(j) in range(97, 110):
				s1 += 1
			if ord(j) in range(78, 91):
				s2 += 1
			if s1 != 0 and s2 != 0:
				flag = True
				break
			if ord(j) not in range(97, 110) and ord(j) not in range(78, 91):
				flag = True
				break
		if flag == True:
			print('NO')
			fail = True
			break
	if fail == False:
		print('YES')


for _ in range(int(input())):
	a = [x for x in input().split()]
	n = int(a[0])
	a = a[1:]
	flag = True
	for i in a:
		if i.islower():
			for j in i:
				if not (ord(j) >= 97 and ord(j) <= 109):
					flag = False
					break
			if not flag:
				break
		elif i.isupper():
			for j in i:
				if not (ord(j) >= 78 and ord(j) <= 90):
					flag = False
					break
			if not flag:
				break
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin
input = stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())

def getvals():
	while True:
		yield from input().split()

def tri(n):
	return n * (n + 1) // 2

def smallest_first(m, n):
	return (min(m, n), max(m, n))
limits = {'lower': ['a', 'm'], 'upper': ['N', 'Z']}
(success, failure) = ('YES', 'NO')

def is_lcl(s):
	return True if all([s.islower(), min(s) >= limits['lower'][0], max(s) <= limits['lower'][1]]) else False

def is_ucl(s):
	return True if all([s.isupper(), min(s) >= limits['upper'][0], max(s) <= limits['upper'][1]]) else False

def solve(s):
	for word in s:
		if all([not is_lcl(word), not is_ucl(word)]):
			return failure
	return success

def do_codechef():
	for t in rii():
		s = si().split()
		print(solve(s[1:]))
do_codechef()
exit()


t = int(input())
for _ in range(t):
	l = list(input().split())
	n = int(l[0])
	l.pop(0)
	f = False
	for s in l:
		sf = cf = False
		for i in s:
			if 'a' <= i <= 'm':
				sf = True
			elif 'N' <= i <= 'Z':
				cf = True
			if sf == True and cf == True:
				print('NO')
				f = True
				break
			if not 'a' <= i <= 'm' and (not 'N' <= i <= 'Z'):
				print('NO')
				f = True
				break
		if f == True:
			break
	else:
		print('YES')