#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, cnt = 0;
  cin >> n;
  vector<int> a(n), d(100005);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    cnt += a.at(i);
    d.at(a.at(i))++;
  }
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b.at(i) >> c.at(i);
    cnt += d.at(b.at(i)) * (c.at(i) - b.at(i));
    d.at(b.at(i)) = 0;
    cout << cnt << endl;
  }
  return 0;
}
