t,n=map(int,input().split()) dic={} for t1 in range(t): x,y=input().split() dic[x]=y for i in range(n): a=input() print(dic[a],end=" ") print()