dic = {}
n = int(input())
for i in range(n):
palavra, adjetivo = input().split()
dic[palavra] = adjetivo
frase = input().split()
for palavra in frase:
if palavra in dic:
print(dic[palavra])
#https://pt.stackoverflow.com/q/346650/101
ZGljID0ge30KbiA9IGludChpbnB1dCgpKSAKZm9yIGkgaW4gcmFuZ2Uobik6CiAgICBwYWxhdnJhLCBhZGpldGl2byA9IGlucHV0KCkuc3BsaXQoKQogICAgZGljW3BhbGF2cmFdID0gYWRqZXRpdm8KZnJhc2UgPSBpbnB1dCgpLnNwbGl0KCkKZm9yIHBhbGF2cmEgaW4gZnJhc2U6CiAgICBpZiBwYWxhdnJhIGluIGRpYzoKICAgICAgICBwcmludChkaWNbcGFsYXZyYV0pCgojaHR0cHM6Ly9wdC5zdGFja292ZXJmbG93LmNvbS9xLzM0NjY1MC8xMDE=