loop do
n = gets.to_i

if n == 0 then
  break
end

from = Array.new
to = Array.new

n.times{
  (a, b) = gets.split  
  from.push(a)
  to.push(b)
}

n = gets.to_i

n.times{
  c = gets.strip
  if i = from.index(c) then
    print to[i]
  elsif
    print c
  end
}
puts ""

end