t,n = map(int,input().split()) dic = {} for i in range(t): a,b = input().split() dic[a] = b for i in range(n):print(dic[input()],end = (' ' if i != n-1 else ''))