#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  vector<long long> v[100001];
  long long n, c, b, q, sum = 0;
  cin >> n;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    for (auto &it : v[b]) {
      sum -= b;
      a[it] = c;
      v[c].push_back(it);
      sum += c;
    }
    v[b].clear();
    sum -= a[b];
    a[b] = c;
    sum += a[b];
    cout << sum << endl;
  }
}
signed main() {
  long long n = 1;
  while (n--) solve();
  return 0;
}
