t,n=map(int,input().split()) dictl={} for i in range(t): r=input().split() dictl[r[0]]=r[1] for i in range(n): print(dictl[input()]+" ",end="")