#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> A;
  map<int64_t, int64_t> d;
  for (int64_t i = 0; i < n; i++) {
    int64_t a;
    cin >> a;
    A.push_back(a);
    if (d.count(a)) {
      d[a] += 1;
    } else {
      d[a] = 1;
    }
  }
  unsigned long long ans = accumulate(A.begin(), A.end(), 0);
  int64_t q;
  cin >> q;
  for (int64_t i = 0; i < q; i++) {
    int64_t b, c;
    cin >> b >> c;
    if (d.count(b)) {
      ans += c * d[b];
      ans -= d[b] * b;
      if (d.count(c)) {
        d[c] += d[b];
      } else {
        d[c] = d[b];
      }
      d[b] = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
