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]);
  // console.log(N);
  // console.log(A);
  // console.log(Q);
  let resultArray = new Map();
  for (let i = 0; i < A.length; i++) {
    let counter = resultArray.get(A[i]) ? parseInt(resultArray.get(A[i])) : 0;
    resultArray.set(A[i], counter + 1);
  }

  let answer = "";
  for (let j = 0; j < Q; j++) {
    let result = 0;
    let changeArray = array[3 + j].trim().split(" ");
    let changeValue = resultArray.get(changeArray[0])
      ? parseInt(resultArray.get(changeArray[0]))
      : 0;
    let nowValue = resultArray.get(changeArray[1])
      ? parseInt(resultArray.get(changeArray[1]))
      : 0;
    resultArray.delete(changeArray[0]);
    resultArray.set(changeArray[1], changeValue + nowValue);
    for (var [key, value] of resultArray) {
      result += parseInt(key) * parseInt(value);
    }
    answer += result + "\n";
  }
  answer = answer.slice(0, -1);
  console.log(answer);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main("4\n1 2 3 4\n3\n1 2\n3 4\n2 4");
