#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, t = 0, v = 0;
  vector<int> A, B, C;
  vector<int> A_copy;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> t;
    A_copy.push_back(t);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> t >> v;
    B.push_back(t);
    C.push_back(v);
  }
  A = A_copy;
  for (int i = 0; i < Q; i++) {
    int sum = 0;
    for (int t = 0; t < N; t++) {
      if (A[t] == B[i]) {
        A[t] = C[i];
      }
      sum += A[t];
    }
    cout << sum << endl;
  }
  return 0;
}
