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