N = gets.to_i
nums = gets.split.map(&:to_i)
Q = gets.to_i
sums = nums.sum
Q.times{
  b, c = gets.split.map(&:to_i)
  count = nums.count(b)
  res = c*count - b*count
  sums += res
  p sums
  count.times{
    nums.delete(b)
    nums.push(c)
  }
}