#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> occ(1e5 + 10);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    sum += (1LL * num);
    occ[num]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (occ[a] > 0) {
      sum -= (occ[a] * a);
      sum += (b * occ[a]);
      occ[b] += occ[a];
      occ[a] = 0;
    }
    cout << sum << "\n";
  }
}
