N = gets.to_i
arr = gets.split.map(&:to_i)
Q = gets.to_i
ans = arr.inject(:+)
Q.times do |i|
	a, b = gets.split.map(&:to_i)
	many =  arr.count(a)
	ans += (b - a) * many
	arr.map!{|x| x==a ? b : x}
	p ans
end