import * as fs from "fs";

// inputで受け取り配列化する
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const N = input.shift();
let A = input.shift().split(" ").map(Number);

const Q = input.shift();

const S = input.map((item) => item.split(" ").map(Number));

for (const item of S) {
  const target = item[0];
  const val = item[1];
  const arr = A.map((item) => {
    if (item === target) {
      return val;
    } else {
      return item;
    }
  });
  A = arr;
  console.log(arr.reduce((pre, cur) => pre + cur));
}
