#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
using P = pair<int, int>;
vector<ll> memo[100005];
int main(void) {
  ll n, q;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    memo[a[i]].push_back(i);
    ans += a[i];
  }
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    ll b, c;
    cin >> b >> c;
    for (ll index : memo[b]) {
      ll now = a[index];
      a[index] = c;
      memo[c].push_back(index);
      ans = ans + c - now;
    }
    cout << ans << endl;
  }
  return 0;
}
