def exchange(str, bef, aft)
	if str == bef
		return aft
	else
		return str
	end
end
$results=[]
ctn=0
n=gets.to_i
a,b=Array.new(n), Array.new(n)
n.times do |i|
	a[i],b[i]=gets.chomp.split
end

gets.to_i.times do
	str=gets.chomp
	result=str
	while !(ctn==n||result!=str)
		result = exchange(str, a[ctn], b[ctn])
		ctn+=1
	end
	$results<<result
	ctn=0
end
puts $results.join