function Main(input) {
  input = input.split('\n');
  const n = +input[0];
  let a = input[1].split(' ').map(Number);
  const q = +input[2];
  const bc = input.slice(3);
  for (let i = 0; i < q; i++) {
    const [b, c] = bc[i].split(' ').map(Number);
    let sum = 0;
    a = a.map(num => {
      let next = num;
      if (num === b) {
        next = c;
      }
      sum += next;
      return next;
    })
    console.log(sum);
  }
}
  
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));