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