while true
  n = gets.to_i
  if n == 0
    break
  end

  i = 0
  h = Array.new(n)
  while i < n
    h[i] =gets.chomp.split(" ")
    i += 1
  end

  m = gets.to_i
  i = 0
  out = ""

  while i < m
    x  = gets.chomp
    j = 0
    while j < n
      if x == h[j][0]
        x = h[j][1]
        break
       end
      j += 1
    end
    out += x
    i+= 1
  end

  puts out
end