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