n = gets.chomp.to_i
a = gets.chomp.split(" ").map { |e|e.to_i  }
aNum = a.uniq
aCount = Array.new(100000,0)
ans = []

aNum.each do |i|
  aCount[i - 1] = a.count(i)
end

sum = 0
for i in 0..100000 - 1 do
  sum += (i + 1) * aCount[i]
end

q = gets.chomp.to_i
q.times do
  b, c = gets.chomp.split(" ").map { |e|e.to_i  }
  if aCount[b - 1] != 0
    sum += aCount[b - 1] * (c - b)
    aCount[c - 1] += aCount[b - 1]
    aCount[b - 1] = 0
  else
  end
  ans << sum
end

puts ans
