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