#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> dates;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dates[x]++;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int b, c;
    cin >> b >> c;
    dates[c] += dates[b];
    dates.erase(b);
    long long ans = 0;
    for (auto &a : dates) {
      ans += (long long)a.first * a.second;
    }
    cout << ans << endl;
  }
}
