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