t,n=map(int,input().split()) dic={} for t1 in range(t): x,y=input().split() dic[x]=y s=[] for t2 in range(n): search=input() c=dic[search] s.append(c) for t3 in s[:-1]: print(t3,end=" ") print(s[-1])