Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that is what happened to them. On the happy side of things, a language may be dead, but some of its words may continue to be used in other languages.

Using something called as the Internet, you have acquired a dictionary of N words of a forgotten language. Meanwhile, you also know K phrases used in modern languages. For each of the words of the forgotten language, your task is to determine whether the word is still in use in any of these K modern phrases or not.

-----Input-----

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of a test case description contains two space separated positive integers N and K.

The second line of the description contains N strings denoting a dictionary of the forgotten language.

Each of the next K lines of the description starts with one positive integer L denoting the number of words in the corresponding phrase in modern languages. The integer is followed by L strings (not necessarily distinct) denoting the phrase.

-----Output-----

For each test case, output a single line containing N tokens (space-separated): if the ith word of the dictionary exists in at least one phrase in modern languages, then you should output YES as the ith token, otherwise NO.

-----Constraints-----
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 100
- 1 ≤ K, L ≤ 50
- 1 ≤ length of any string in the input ≤ 5

-----Example-----
Input:
2
3 2
piygu ezyfo rzotm
1 piygu
6 tefwz tefwz piygu ezyfo tefwz piygu
4 1
kssdy tjzhy ljzym kegqz
4 kegqz kegqz kegqz vxvyj

Output:
YES YES NO 
NO NO NO YES

Difficulty: EASY
Tags: String algorithms

Data structures

Implementation

Complete search
Skill types: Data structures

Complete search

Starter code:

Solutions:
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	old = list(input().split())
	new = []
	for i in range(K):
		list1 = list(input().split())
		new += list1
	for i in old:
		if i in new:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')


test_case = int(input())
for w in range(test_case):
	(n, k) = map(int, input().split())
	l = list(map(str, input().split()))
	ans = []
	for q in range(k):
		l2 = list(map(str, input().split()))
		ans.extend(l2[1:])
	for i in l:
		if i in ans:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


T = int(input())
for i in range(T):
	(x, y) = map(int, input().split())
	string = list(map(str, input().split()))
	lst = []
	for i in range(y):
		lst += [i for i in input().split()]
	res = []
	for i in range(x):
		if string[i] not in lst:
			res.append('NO')
		else:
			res.append('YES')
	print(*res)


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	p = list(map(str, input().split()))
	l = []
	for i in range(0, k):
		l += list(map(str, input().split()))
	for j in p:
		if j in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


casos = int(input())
for i in range(casos):
	(numero_viejas, numero_casos) = map(int, input().split())
	palabras_viejas = list(input().split())
	lista = []
	lista_2 = []
	for i in range(numero_casos):
		x = list(input().split())
		y = set(x[1:])
		for i in y:
			lista.append(i)
	for i in palabras_viejas:
		if i in lista:
			lista_2.append('YES')
		else:
			lista_2.append('NO')
	print(*lista_2, sep=' ')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = input()
	l = l.split(' ')
	d = ''
	for _ in range(b):
		d += input() + ' '
		s = ''
		for i in l:
			if i in d:
				s += 'YES '
			else:
				s += 'NO '
	print(s)


T = int(input())
for _ in range(T):
	(N, K) = tuple((int(_) for _ in input().split()))
	forgotten = input().split()
	phrases = ''.join(tuple((input() for _ in range(K))))
	print(' '.join(tuple(('YES' if k in phrases else 'NO' for k in forgotten))))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	word = input().split()
	a = set()
	for i in range(n):
		a = a.union(set(input().split()))
	for i in range(m):
		if word[i] in a:
			word[i] = 'YES'
		else:
			word[i] = 'NO'
	print(*word)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	old = input().split()
	a = [input() for i in range(k)]
	d = {}
	for j in old:
		d[j] = 'NO'
	for i in old:
		for j in a:
			if d.get(i) == 'NO':
				if i in j:
					d[i] = 'YES'
	b = [i for i in d.values()]
	print(*b)


n = int(input())
(l, dictonary) = ([], [])
for i in range(n):
	(listSize, numOfDict) = map(int, input().split())
	listOfelement = list(map(str, input().split()))
	for i in range(numOfDict):
		dictonary += list(map(str, input().split()))
	for ele in listOfelement:
		if ele in dictonary:
			l.append('YES')
		else:
			l.append('NO')
	for out in l:
		print(out, end=' ')
	print()
	(dictonary, l) = ([], [])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ln = list(input().split())
	l = [0] * n
	lall = []
	for i in range(k):
		lk = list(input().split())
		lall = lall + lk[1:]
	for i in range(n):
		if ln[i] in lall:
			l[i] = 1
	for i in range(n):
		if l[i] == 1:
			print('YES ', end='')
		else:
			print('NO ', end='')
	print('\n', end='')


t = int(input())
for z in range(t):
	(n, q) = map(int, input().split())
	s = list(input().split())
	p = ''
	for i in range(q):
		p = p + input() + ' '
	for j in s:
		if j in p:
			print('YES', end=' ')
			s[s.index(j)] = '69'
		else:
			print('NO', end=' ')
	print()


from collections import Counter

def computeDictionary(words, setWords):
	dictWords = {}
	res = ''
	for w in words:
		dictWords[w] = 'NO'
	for (num, string) in setWords:
		for word in string:
			if word in dictWords:
				dictWords[word] = 'YES'
	for element in dictWords.values():
		res += element + ' '
	return res
tc = int(input())
for _ in range(tc):
	(wordnum, lines) = map(int, input().split())
	words = list(map(str, input().split()))
	setWords = []
	for _ in range(lines):
		s = list(map(str, input().split()))
		num = int(s[0])
		setWords.append([num, s[1:]])
	res = computeDictionary(words, setWords)
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = [str(x) for x in input().split()]
	kl1 = []
	for _ in range(k):
		kl = [str(x) for x in input().split()]
		kl.remove(kl[0])
		kl1.extend(kl)
	set(kl1)
	for j in l:
		if j in kl1:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('\n')


for i in range(int(input())):
	(i1, i2) = map(int, input().split())
	lst1 = input().split()
	lst = []
	for j in range(i2):
		lst2 = input().split()
		lst.extend(lst2[1:])
	for k in range(0, len(lst1)):
		if lst1[k] in lst:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(str, input().split()))
	li = []
	t = 0
	for i in range(k):
		a = list(map(str, input().split()))
		l = len(a)
		for j in range(l):
			li.append(a[j])
	d = []
	for i in range(n):
		if s[i] in li:
			d.append('YES')
		else:
			d.append('NO')
	print(*d)


for i in range(0, int(input())):
	(n, k) = map(int, input().split())
	forg = list(input().split())
	li = []
	for i in range(k):
		li += input().split()
	ans = ''
	for x in forg:
		if x in li:
			ans += 'YES '
		else:
			ans += 'NO '
	print(ans)


t = int(input(''))
if 1 <= t <= 20:
	for _ in range(t):
		(n, k) = map(int, input('').split())
		ln = input('').split()
		for i in range(k):
			kn = input('').split()
			m = int(kn[0])
			for j in range(n):
				if ln[j] in kn[1:]:
					ln[j] = 1
		for k in range(n):
			if ln[k] == 1:
				print('YES', end=' ')
			else:
				print('NO', end=' ')
		print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	old = [j for j in input().split()]
	new = []
	for i in range(k):
		res = [m for m in input().split()]
		res.pop(0)
		new.append(res)
	ans = [y for x in new for y in x]
	result = []
	for i in range(len(old)):
		if old[i] in ans:
			result.append('YES')
		else:
			result.append('NO')
	print(*result)


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	arr = list(input().split())
	c = []
	for i in range(k):
		brr = list(input().split())
		c += brr
	for i in arr:
		if i in c:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	ln = list(map(str, input().split()))
	for i in range(k):
		lk = list(map(str, input().split()))
		l = l + lk
	for a in ln:
		if a in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ns = [i for i in input().split()]
	d = {}
	for i in ns:
		d[i] = False
	for i in range(k):
		ks = list(map(str, input().split()))
		for j in ks:
			if j in d:
				d[j] = True
	for i in ns:
		if d[i] == True:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	forgotten_lang = list(input().split())
	new_lang = []
	for _ in range(K):
		sttr = list(map(str, input().split()))
		new_lang += sttr[1:]
	for x in forgotten_lang:
		if x in new_lang:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	strings = input().split()
	res = ''
	for i in range(k):
		modernlanguage = input().split()
		modernlanguage.remove(modernlanguage[0])
		res = res + ''.join(modernlanguage)
	res1 = []
	for i in range(len(strings)):
		if strings[i] in res:
			res1.append('YES')
		else:
			res1.append('NO')
	print(*res1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = input().split()
	hs = set()
	for i in range(k):
		temp = input().split()[1:]
		for val in temp:
			hs.add(val)
	count = 0
	for val in arr:
		if val in hs:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


try:
	for _ in range(int(input())):
		(N, K) = map(int, input().split())
		words = input().split()
		phrases = []
		for k in range(K):
			phrases.extend(input().split())
		used = []
		for w in words:
			if w in phrases:
				used.append('YES')
			else:
				used.append('NO')
		print(*used)
except:
	pass


t = int(input())
for ni in range(t):
	(n, k) = map(int, input().split())
	s = input().split()
	count = 0
	out = ['NO'] * n
	for nj in range(k):
		l = input().split()
		l = l[1:]
		for i in range(n):
			if s[i] in l:
				out[i] = 'YES'
	print(*out)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	old = list(input().split())
	new = []
	for i in range(k):
		phrase = input().split()
		new += phrase
	new = set(new)
	for w in old:
		if w in new:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


T = int(input())
for t in range(T):
	phrases = []
	(numword, numphrases) = input().split()
	words = input().split()
	for phrase in range(int(numphrases)):
		phrase = input().split()
		phrase = phrase[1:]
		for word in phrase:
			phrases.append(word)
	for count in range(len(words)):
		if words[count] in phrases:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('\n', end='')


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	dict = list(map(str, input().split()))
	mod_pharse = []
	for m in range(K):
		l = list(map(str, input().split()))
		mod_pharse.extend(l[1:])
	for i in dict:
		if i in mod_pharse:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	f = list(map(str, input().split()))
	z = [0] * k
	for t in range(k):
		z[t] = list(map(str, input().split()))
	chk_ans = []
	ff = 0
	while ff < len(f):
		ans = 0
		nn = 0
		while nn < len(z):
			if f[ff] in z[nn]:
				chk_ans.append('YES')
				ff += 1
				ans += 1
				break
			else:
				nn += 1
				continue
		if ans == 0:
			ff += 1
			chk_ans.append('NO')
	print(*chk_ans)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	words = input().split()
	phrases = []
	for __ in range(K):
		phrases.append(set(input().split()))
	ans = []
	for w in words:
		token = 'NO'
		for p in phrases:
			if w in p:
				token = 'YES'
				break
		ans.append(token)
	print(*ans)


t = int(input())
for i in range(0, t):
	(n, k) = [int(n) for n in input().split()]
	a = input().split()
	b = []
	for j in range(0, k):
		x = input().split()
		for p in range(1, len(x)):
			b.append(x[p])
	r = 0
	for r in range(0, len(a)):
		if b.__contains__(a[r]):
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print(' ')


for x in range(int(input())):
	(N, K) = list(map(int, input().split()))
	dictionary = list(map(str, input().split()))
	answer = []
	modern = []
	count = 1
	for x in range(K):
		modern.extend(input().split())
	for x in range(N):
		if dictionary[x] in modern:
			answer.append('YES')
		else:
			answer.append('NO')
	for x in range(len(answer)):
		print(answer[x], end=' ')
	print()


n = int(input())
for i in range(n):
	x = input().split(' ')
	fw = input().split(' ')
	mw = []
	for w in range(int(x[1])):
		mw.append(input().split(' ')[1:])
	mw1 = [t for p in mw for t in p]
	l = []
	for j in range(len(fw)):
		if fw[j] in mw1:
			l.append('YES')
		else:
			l.append('NO')
	print(' '.join(l))


testcases = int(input())
for i in range(testcases):
	(n, k) = input().split()
	data = input().split()
	res = []
	for i in range(int(k)):
		string = input().split()
		string.pop(0)
		for i in string:
			res.append(i)
	for i in range(len(data)):
		if data[i] in res:
			data[i] = 'YES'
		else:
			data[i] = 'NO'
	print(*data)


t = int(input())
ans1 = list()
for i in range(t):
	n = list(map(int, input().split()))
	s = list(map(str, input().split()))
	ans = list()
	for j in range(n[1]):
		a = list(map(str, input().split()))
		ans.append(a)
	d = list()
	for j in ans:
		d = d + j
	yo = ''
	for k in range(len(s)):
		if s[k] in d:
			yo = yo + 'YES' + ' '
		else:
			yo = yo + 'NO' + ' '
	ans1.append(yo)
for l in ans1:
	print(l)


for j in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input().split())
	d = []
	for i in range(k):
		d += [i for i in input().split()]
	l = []
	for i in range(len(a)):
		if a[i] in d:
			l.append('YES')
		else:
			l.append('NO')
	print(*l)


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	s = list(map(str, input().split(' ')))
	x = []
	res = []
	for i in range(k):
		l = list(map(str, input().split(' ')))
		for i in range(1, len(l)):
			if l[i] in s:
				if l[i] not in x:
					x.append(l[i])
	for i in s:
		if i in x:
			res.append('YES')
		else:
			res.append('NO')
	print(*res)


t = int(input())
for t_ in range(t):
	(n, k) = map(int, input().split())
	dictn = input().split()
	phrase = []
	for i in range(k):
		phrase += input().split()[1:]
	for word in dictn:
		if word in phrase:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


def solve():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		aitihasik_bhasa = list(map(str, input().split()))
		d = {}
		for b in aitihasik_bhasa:
			d[b] = False
		for _ in range(k):
			vakya = list(map(str, input().split()))
			vakya = vakya[1:]
			for v in vakya:
				if v in d:
					d[v] = True
		for v in aitihasik_bhasa:
			if d[v]:
				print('YES', end=' ')
			else:
				print('NO', end=' ')
		print()

def __starting_point():
	solve()
__starting_point()


test = int(input())
for i in range(test):
	(n, k) = map(int, input().split())
	fld = list(map(str, input().split()))
	sent = ''
	for i in range(k):
		sent = sent + input() + ' '
	for a in fld:
		if a in sent:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(input().split(' '))
	l = []
	for _ in range(k):
		l = l + list(input().split(' '))[1:]
	for i in range(n):
		if l1[i] in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = input().split(' ')
	x = []
	for i in range(k):
		x += input().split(' ')
	for i in l:
		if i in x:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = input().split()
	m = []
	for i in range(k):
		alph = input().split()
		for k in range(1, len(alph)):
			m.append(alph[k])
	m = list(set(m))
	for i in arr:
		if i in m:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('\n')


T = int(input())
for i in range(0, T):
	(N, K) = [int(N) for N in input().split()]
	a = input().split()
	b = []
	for j in range(0, K):
		x = input().split()
		for t in range(1, len(x)):
			b.append(x[t])
	r = 0
	for r in range(0, len(a)):
		if b.__contains__(a[r]):
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print(' ')


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	list_old = input().split()
	list_new = []
	for a in range(k):
		list_new += input().split()
	sen = ''
	for a in list_old:
		if a in list_new:
			sen += 'YES '
		else:
			sen += 'NO '
	print(sen)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(str, input().split()))
	m = []
	for i in range(k):
		z = list(map(str, input().split()))
		m += z
	for i in l:
		if i in m:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	d = input()
	l = []
	for i in range(k):
		l.append(input())
	ans = 'NO'
	for i in d.split():
		ans = 'NO'
		for j in l:
			if i in j[1:]:
				ans = 'YES'
		print(ans, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [x for x in input().split()]
	s = set()
	for i in range(k):
		for w in input().split():
			s.add(w)
	ans = []
	for i in range(n):
		ans.append('YES') if a[i] in s else ans.append('NO')
	print(' '.join(ans))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = []
	l1 = list(map(str, input().split()))
	for i in range(k):
		l2 = list(map(str, input().split()))
		l = l + l2
	for a in l1:
		if a in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


test = int(input())
for _ in range(0, test):
	(words, phrases) = map(int, input().split())
	listOfPhrases = set()
	words = list(input().split())
	for _ in range(0, phrases):
		newset = set(input().split())
		listOfPhrases = listOfPhrases.union(newset)
	for x in words:
		if x in listOfPhrases:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


t = int(input())
while t:
	t -= 1
	nk = input().split()
	n = input().split()
	k = []
	for i in range(int(nk[1])):
		k.extend(input().split()[1:])
	for i in n:
		if i in k:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for i in range(int(input())):
	(x, y) = list(map(int, input().split()))
	s = input().split()
	w = ' '
	for j in range(y):
		z = input()
		w += z
	for k in s:
		if k in w:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dic = list(map(str, input().split()))
	wordDic = {}
	ansList = []
	for i in range(k):
		p = list(map(str, input().split()))
		num = int(p[0])
		p.remove(p[0])
		for j in dic:
			if j in p:
				if j in wordDic:
					wordDic[j] += 1
				else:
					wordDic[j] = 1
			elif j in wordDic:
				wordDic[j] += 0
			else:
				wordDic[j] = 0
	for c in wordDic:
		if wordDic[c] >= 1:
			ansList.append('YES')
		else:
			ansList.append('NO')
	print(*ansList)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	s = list(input().split())
	count = 0
	out = ['NO'] * N
	for nj in range(K):
		l = input().split()
		l = l[1:]
		for i in range(N):
			if s[i] in l:
				out[i] = 'YES'
	print(*out)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input().split())
	s1 = ''
	for i in range(k):
		p = input()
		s1 += ' ' + p
	for j in s:
		if j in s1:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


try:
	test_cases = int(input())
	for _ in range(test_cases):
		(n, k) = input().split()
		dictOfForgottenWord = list(input().split())
		modernDict = ''
		for i in range(int(k)):
			modernDict += ' ' + input()
		newModernDict = list(set(list(modernDict.split(' '))))
		for i in dictOfForgottenWord:
			if i in newModernDict:
				print('YES', end=' ')
			else:
				print('NO', end=' ')
		print()
except:
	pass


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input().split())
	c = []
	for i in range(k):
		b = list(input().split())
		c += b
	for i in a:
		if i in c:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(u, g) = map(int, input().split())
	dic = input().split()
	r = ''
	for i in range(g):
		x = input()
		r += x
	for i in dic:
		if i in r:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(str, input().split()))
	b = []
	for _ in range(k):
		a = list(map(str, input().split()))
		b.extend(a[1:])
	c = []
	for i in s:
		if i in b:
			c.append('YES')
		else:
			c.append('NO')
	print(*c)


t = int(input())
for b in range(t):
	(n, k) = [int(x) for x in input().split()]
	answer = ['NO'] * n
	l = [str(x) for x in input().split()]
	for i in range(k):
		lin = [str(x) for x in input().split()]
		for j in range(n):
			for k in lin:
				if k == l[j]:
					answer[j] = 'YES'
					break
	for i in answer:
		print(i, end=' ')
	print()


t = int(input())
while t != 0:
	t -= 1
	(n, m) = map(int, input().split())
	d = {}
	s = input().split()
	for word in s:
		d[word] = False
	for i in range(m):
		sab = input().split()
		for i in range(1, len(sab)):
			if sab[i] in d:
				d[sab[i]] = True
	for (x, y) in d.items():
		if y:
			print('YES', end=' ')
			continue
		print('NO', end=' ')
	print()


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	a = list(map(str, input().split()))
	k = []
	for i in range(n):
		k += list(map(str, input().split()))
	for j in a:
		if j in k:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for x in range(int(input())):
	(N, K) = list(map(int, input().split()))
	dictionary = list(map(str, input().split()))
	answer = []
	modern = []
	for x in range(K):
		modern.extend(input().split())
	for x in range(N):
		if dictionary[x] in modern:
			answer.append('YES')
		else:
			answer.append('NO')
	print(' '.join(answer))


try:
	t = int(input())
	while t > 0:
		(n, q) = map(int, input().split())
		A = [j for j in input().split()]
		tmp = []
		while q > 0:
			tmp += [j for j in input().split()]
			q -= 1
		i = 0
		while n > i:
			if A[i] in tmp:
				print('YES', end=' ')
			else:
				print('NO', end=' ')
			i += 1
		print()
		t -= 1
except:
	pass


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input().split()
	x = list(s)
	res = ' '
	u = []
	for _ in range(k):
		y = input().split()
		for i in y:
			if i not in u:
				u.append(i)
	for i in x:
		if i in u:
			res = res + 'YES' + ' '
		else:
			res = res + 'NO' + ' '
	print(res)


t = input()
for c in range(0, int(t)):
	(n, k) = input().split()
	dic = input().split()
	out = ''
	found = 0
	fc = []
	for w in dic:
		fc.append(0)
	for x in range(0, int(k)):
		found = 0
		ph = input().split()
		for y in range(0, int(n)):
			if fc[y] == 0:
				if dic[y] in ph:
					fc[y] = 1
	for z in range(0, int(n)):
		if fc[z] == 1:
			out = out + 'YES '
		else:
			out = out + 'NO '
	print(out)


t = int(input())
while t:
	lst = input().split()
	(n, k) = (lst[0], lst[1])
	lstn = input().split()
	count = int(k)
	lstk = []
	while count:
		lstk.extend(input().split())
		count = count - 1
	for i in lstn:
		if i in lstk:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('\n')
	t = t - 1


t = int(input())
while t:
	(n, k) = map(int, input().split())
	p = list(map(str, input().split()))
	l = []
	while k:
		s = list(map(str, input().split()))
		l += s[1:]
		k -= 1
	for i in p:
		if i in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()
	t -= 1


T = int(input())
for i in range(T):
	(N, K) = [int(x) for x in input().split()]
	S = [str(x) for x in input().split()]
	M = []
	for j in range(K):
		L = [str(x) for x in input().split()]
		for k in range(1, len(L)):
			M.append(L[k])
	M = list(set(M))
	Y = []
	for x in S:
		if x in M:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('\n')


t = int(input())
i = 0
while i < t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	s = []
	ans = [0] * n
	s = input().split()
	j = 0
	while j < k:
		l = []
		l = input().split()
		m = 0
		while m < n:
			if s[m] in l:
				ans[m] = 1
			m += 1
		j += 1
	d = 0
	while d < n:
		if ans[d] == 0:
			print('NO', end=' ')
		else:
			print('YES', end=' ')
		d += 1
	print('')
	i += 1


t = int(input())
for z in range(t):
	(a, b) = [int(x) for x in input().split()]
	s = input().split()
	x = []
	for i in range(b):
		y = input().split()
		x = x + y
	l = set(x)
	for i in s:
		if i in l:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	lisf = input().split()
	lism = []
	lis = []
	for i in range(k):
		l = input().split()
		lis.append(l)
	for i in range(len(lis)):
		for j in range(len(lis[i])):
			if len(lis[i][j]) > 1:
				lism.append(lis[i][j])
	a = []
	for i in range(len(lisf)):
		if lisf[i] in lism:
			a.append('YES')
		else:
			a.append('NO')
	print(' '.join(a))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	l = list(map(str, input().split()))
	c = []
	while m:
		s = list(map(str, input().split()))
		c += s
		m = m - 1
	for i in l:
		if i in c:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')
	t = t - 1


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [x for x in input().split()]
	global_list = []
	for j in range(k):
		for (indi, x) in enumerate(input().split()):
			if indi > 0:
				global_list.append(x)
	for str_ in a:
		if str_ in global_list:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print('')


def p_input():
	tot = int(input())
	dicts = []
	for i in range(tot):
		n = [int(x) for (j, x) in enumerate(input().split()) if j < 2]
		dicts = input().split()[:n[0]]
		sents = []
		for _ in range(n[1]):
			sent = input().split()
			sents += sent[1:int(sent[0]) + 1]
		print(' '.join(('YES' if x in sents else 'NO' for x in dicts)))

def __starting_point():
	p_input()
__starting_point()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(str, input().split(' ')))
	new_list = []
	for i in range(k):
		a = input().split()
		for k in range(1, len(a)):
			new_list.append(a[k])
	new_list = list(set(new_list))
	for l in arr:
		if l in new_list:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	word = list(input().split())
	li = []
	for x in range(k):
		l = list(input().split())
		li += l
	for x in word:
		if x in li:
			print('YES', end=' ')
		else:
			print('NO', end=' ')
	print()