import { readFileSync } from "fs";

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

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

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

    arr = arr.map((ele) => {
      if (ele === B) {
        sum = sum + C;
        return C;
      }
      sum = sum + ele;
      return ele;
    });

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

main(read());
