def sum(aas)
  result = 0
  aas.each do |k, v|
    result += k * v
  end
  result
end

n = gets.chomp.to_i
as = gets.chomp.split(' ').map(&:to_i)

aas =
  as.each_with_object({}) do |a, objects| 
    objects[a] = objects[a].to_i + 1
  end

q = gets.chomp.to_i
before_sum = nil
q.times do
  b, c = gets.chomp.split(' ').map(&:to_i)
  count = aas.delete(b)
  if count
    aas[c] = aas[c].to_i + count
  end
  # p aas
  if before_sum == nil || count != nil
    before_sum = sum(aas)
  end
  puts before_sum
end
