#include <bits/stdc++.h>
using namespace std;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
}
signed main() {
  init();
  int n, s = 0, q, t;
  cin >> n;
  vector<int> v(100001, 0);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> t;
    v[t]++;
    s += t;
  }
  cin >> q;
  int a, b;
  while (q--) {
    cin >> a >> b;
    if (v[a] != 0) {
      s = s + v[a] * (b - a);
      v[b] = v[a] + v[b];
      v[a] = 0;
    }
    cout << s << endl;
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
