def main
  n = gets.chomp.to_i
  trans = {}
  n.times do |i|
    x, y = gets.chomp.split(" ")
    trans[x] = y
  end
  m = gets.chomp.to_i
  m.times do |i|
    x = gets.chomp
    print trans[x] || x
  end
  print "\n"
end

main