#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll sz = 1e5 + 10;
ll bt[sz], arr[sz];
unordered_map<ll, vector<ll>> mp;
ll n, q;
void upd(ll p, ll x) {
  for (ll i = p; i <= n; i += i & -i) {
    bt[i] += x;
  }
}
ll sum(ll p) {
  ll res = 0;
  for (ll i = p; i; i -= i & -i) {
    res += bt[i];
  }
  return res;
}
int main() {
  ll tmp;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> tmp;
    mp[tmp].push_back(i);
    arr[i] = tmp;
    upd(i, tmp);
  }
  cin >> q;
  while (q--) {
    ll b, c;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      for (int idx : mp[b]) {
        upd(idx, c - b);
        mp[c].push_back(idx);
      }
      mp.erase(b);
    }
    cout << sum(n) << "\n";
  }
  return 0;
}
