#include <bits/stdc++.h>
int main() {
  int N, Q;
  std::cin >> N;
  int* A = new int[N];
  int i, j;
  for (i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::cin >> Q;
  int* B = new int[Q];
  int* C = new int[Q];
  for (i = 0; i < Q; i++) {
    std::cin >> B[i] >> C[i];
  }
  int count;
  for (j = 0; j < Q; j++) {
    count = 0;
    for (i = 0; i < N; i++) {
      if (A[i] == B[j]) {
        A[i] = C[j];
      }
      count = count + A[i];
    }
    std::cout << count << std::endl;
  }
  delete[] A;
  delete[] B;
  delete[] C;
  return 0;
}
