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