#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, sum = 0;
  cin >> n;
  ll a[n + 2];
  vector<vector<int>> vp(100005, vector<int>());
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    vp[a[i]].push_back(a[i]);
  }
  ll k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    ll x, y, d;
    cin >> x >> y;
    for (ll j = 0; j < vp[x].size(); j++) {
      sum -= vp[x][j];
      sum += y;
      vp[y].push_back(y);
    }
    vp[a[x]].clear();
    cout << sum << endl;
  }
}
