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