n,m = map(int,input().split()) d={} for i in range(n): a = input().split() d[a[0]]=a[1] for i in range(m): b=input() print(d[b],end=" ") print()