#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> b(n);
  map<int, int> ma;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    b[i] = s;
    ma[s]++;
  }
  cin >> q;
  int B, C;
  for (int i = 0; i < q; i++) {
    cin >> B >> C;
    ma[C] += ma[B];
    ma[B] = 0;
    long long ans = 0;
    for (auto itr = ma.begin(); itr != ma.end(); ++itr) {
      ans += (itr->first) * (itr->second);
    }
    cout << ans << endl;
  }
  return 0;
}
