
const main = (input) => {
  const ip = input.trim().split('\n')
  const arr = ip[1].split(' ').map(v => parseInt(v, 10))
  const n_q = parseInt(ip[2])
  const q = ip.slice(3)

  const nums = {}
  let currentSum = 0
  
  for (let v of arr) {
    currentSum += v
    nums[v] = ~~nums[v] + 1
  }

  for (let i = 0; i < n_q; i++) {
    const [pre, v] = q[i].split(' ').map(v => parseInt(v, 10))
    const dif = v - pre
    const count = ~~nums[pre]

    nums[v] = ~~nums[v] + count

    currentSum += dif * count
    console.log(currentSum)
  }
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))