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

Starter code:

Solutions:
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()# cook your dish here


# cook your dish here
t=int(input())
for w in range(t):
 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):
 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)
 
  


# cook your dish here
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()


# cook your dish here
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

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 = [], []
    




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

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()

# cook your dish here
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()

# cook your dish here
#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 
#O NO NO YES 


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()
  


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 _ 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)

try:
 # cook your code here
 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

# cook your dish here
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 _ 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)

# cook your dish here
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()

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())
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)

# cook your dish here
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()

# cook your dish here
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()

# cook your dish here
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()
  

# cook your dish here
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(" ")

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(' ')

'''
  Problem : Mahasena
  Author @ Rakesh Kumar
  cpp.rakesh@gmail.com
  Date : 29/01/2021
'''

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()

# cook your dish here
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()