#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> arr(n);
  map<int, int> rel;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    rel[arr[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (rel.count(a)) {
      rel[b] += rel[a];
      sum -= a * rel[a];
      sum += b * rel[a];
      rel[a] = 0;
      cout << sum << "\n";
    } else
      cout << sum << "\n";
  }
  return 0;
}
