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