#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < (Q); i++) cin >> B[i] >> C[i];
  ll res = 0;
  for (int i = 0; i < N; i++) {
    res += A[i];
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
        res += C[i] - B[i];
      }
    }
    cout << res << endl;
  }
  return 0;
}
