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

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

    for (let x = 0; x < arr.length; x++) if (arr[x] === pre) arr[x] = v

    console.log(arr.reduce((a, b) => a + b, 0))
  }

}

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