while true
  n = gets.to_i
  break if n == 0
  c = Array.new(n){gets.split(" ")}.transpose
  m = gets.to_i
  str = ""
  cur = 0
  m.times do
    l = gets.chomp
    idx = c[0].index(l)
    l = c[1][idx] unless idx.nil?
    str += l
  end
  puts str
end