#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  vector<set<int>> idx(100000 + 1);
  long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    idx[a[i]].insert(i);
    s += a[i];
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    if (idx[b].empty())
      cout << s << "\n";
    else {
      s += ((c - b) * (idx[b].size()));
      cout << s << "\n";
      for (int x : idx[b]) {
        a[x] = c;
        idx[c].insert(x);
      }
      idx[b].clear();
    }
  }
}
