#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  long long sum = 0;
  vector<int> x(pow(10, 5) + 1, 0);
  vector<int> a(n), b(q), c(q);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a.at(i);
  cin >> q;
  for (int i = 0; i < q; i++) cin >> b.at(i) >> c.at(i);
  for (int i = 0; i < n; i++) x.at(a.at(i)) += 1;
  for (int i = 0; i < x.size(); i++) sum += x.at(i) * i;
  for (int i = 0; i < q; i++) {
    sum += (c.at(i) - b.at(i)) * x.at(b.at(i));
    x.at(c.at(i)) += x.at(b.at(i));
    x.at(b.at(i)) = 0;
    cout << sum << endl;
  }
}
