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