#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, t, s = 0;
  cin >> n;
  vector<int> v(100069, 0);
  for (int i = 0; i < n; i++) {
    cin >> t;
    v[t] += 1;
    s += t;
  }
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    s -= v[b] * b;
    s += v[b] * c;
    v[c] += v[b];
    v[b] = 0;
    cout << s << "\n";
  }
  return 0;
}
