# Volume5,0501
# Data Conversion

while line = $stdin.gets
	n = line.to_i
	break if n == 0

	table  = Hash.new
	answer = ""
	n.times {
		data = $stdin.gets.split(/\s/)
		table[ data[ 0 ] ] = data[ 1 ]
	}

	m = $stdin.gets.chomp.to_i
	m.times {
		c = $stdin.gets.chomp
		if table.key?( c )
			answer += table[ c ]
		else
			answer += c
		end
	}
	puts answer
end
