t,n=map(int,input().split()) d1={} for i in range(t): k,v=map(str,input().split()) d1[k]=v s="" for i in range(n): k=input() s+=d1[k]+" " print(s)