import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  let N = Number(input[0]);
  let arr = input[1].map(Number);
  const Q = Number(input[2]);
  let B: number;
  let C: number;
  let sum = 0;

  for (let s = 0; s < Q; s++) {
    B = Number(input[s + 3][0]);
    C = Number(input[s + 3][1]);

    for (let t = 0; t < N; t++) {
      if (arr[t] === B) {
        arr[t] = C;
      }

      sum += arr[t];
    }

    console.log(sum);
    sum = 0;
  }
};

main(read());
