
words = Array.new

N = gets.to_i
input = Array.new(N){0}
output = Array.new(N){0}
N.times do |i|
n1,n2 = gets.split.map(&:to_s)
input[i]=n1
output[i]=n2
end

M = gets.to_i

M.times do
	word = gets.chomp.to_s
	ans = word
	N.times do |i|
		if(input[i]===word)
			ans = output[i]
			break
		end
	end
	words.push(ans)
end

M.times do 
	w = words.shift
print(w)
end