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