x,y=map(int,input().split()) d={} for tcase in range(x): a=input().split() d[a[0]]=a[1] for tcase in range(y): a=input() print(d[a],end=' ') print()