const main = input => {
  const inputArray = input.split('\n');
  const n = inputArray[0];
  let a = inputArray[1].split(' ');
  const q = inputArray[2];
  const b = [];
  const c = [];
  for (i = 0; i < q; i ++) {
    const [bi, ci] = inputArray[i + 3].split(' ');
    b.push(bi);
    c.push(ci);

    a = a.map(x => {
      if (x === bi) {
        return ci;
      } else {
        return x;
      }
    });
    console.log(a.reduce((acc, current, index, array) => Number(acc) + Number(current)));
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
