#!/usr/bin/ruby

def main
  n = gets().to_i
  return false if n == 0

  # ????????¨?????????
  rule = Hash.new
  n.times do
    from, to = gets().split(/\s*/)
    rule[from] = to
  end

  # ???????????????
  n = gets().to_i
  str = ''
  n.times do
    ch = gets().chomp!
    if rule[ch]
      str << rule[ch]
    else
      str << ch
    end
  end
  puts str
  return true
end

while(main)
end