n = gets.to_i
table = {}
n.times do
  key,val = gets.chomp.split(" ")
  table[key] = val
end

m = gets.to_i
ans = []*m
0.upto(m-1) do |i|
  ch = gets.chomp
  ch = table[ch] unless table[ch].nil?
  ans[i] = ch
end

puts ans.join