#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < (int)n; i++) cin >> A[i];
  cin >> q;
  vector<int> B(q), C(q);
  for (int i = 0; i < (int)q; i++) cin >> B[i] >> C[i];
  ll ans = 0;
  for (int i = 0; i < (int)n; i++) {
    ans += A[i];
  }
  for (int i = 0; i < (int)q; i++) {
    for (int j = 0; j < (int)n; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
        ans += C[i] - B[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
