t,n=map(int,input().split()) d={} s="" for i in range(t): k,m=input().split() d[k]=m for i in range(n): print(d[input()],end=" ") print()