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