while 0 < n = gets.chomp.to_i
	change = {}
	n.times{a, b = gets.chomp.split(' '); change[a] = b}
	result = []
	gets.chomp.to_i.times do
		input = gets.chomp
		if change[input] == nil
			result << input
		else
			result << change[input]
		end
	end
	puts result.join
end