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