function main(arg) {
  const array = arg.trim().split("\n");
  const N = parseInt(array[0]);
  const A = array[1].trim().split(" ");
  const Q = parseInt(array[2]);
  let resultArray = [];
  for (let i = 0; i < Q; i++) {
    let changeArray = array[Q + i].trim().split(" ");
    for (let j = 0; j < A.length; j++) {
      if (A[j] == changeArray[0]) {
        A.splice(j, 1, changeArray[1]);
      }
    }
    let result = 0;
    for (let j = 0; j < A.length; j++) {
      result += parseInt(A[j]);
    }
    resultArray.push(result);
  }

  let stringResult = "";
  for (let k = 0; k < resultArray.length; k++) {
    if (k == resultArray.length - 1) {
      stringResult += resultArray[k];
    } else {
      stringResult += resultArray[k] + "\n";
    }
  }
  console.log(stringResult);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
