n,q=map(int,input().split())
d=dict()
for i in range(n):
s1,s2=map(str,input().split())
d[s1]=s2
for j in range(q):
s3=input();k=len(s3)
if '.' in s3:
j=s3[::-1].index('.')
i=k-j-1
value=s3[i+1:]
if value in d:
print(d[value])
else:
print('unknown')
else:
print('unknown')