function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ').map(Number)
  const A = inputs[1].split(' ').map(Number)
  const [Q] = inputs[2].split(' ').map(Number)
  const BC = inputs.slice(3).map(e => e.split(' ').map(Number))
  // console.log(A, BC)
  let count = {}
  let sum = 0
  for(let i = 0; i < N; i++) {
    if (count[A[i]] === undefined) count[A[i]] = 0
    count[A[i]] ++
    sum += A[i]
  }
  // console.log(count, sum)
  for (let i = 0; i < Q; i++) {
    if (count[BC[i][0]] === undefined) {
      // console.log(count)
      console.log(sum)
      continue
    }
    if (count[BC[i][1]] === undefined) count[BC[i][1]] = 0
    let diff = BC[i][1] - BC[i][0]
    sum += count[BC[i][0]] * diff
    count[BC[i][1]] += count[BC[i][0]]
    count[BC[i][0]] = 0
    // console.log(count)
    console.log(sum)
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())
