#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> counts;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    if (counts.find(k) == counts.end()) counts[k] = 0;
    counts[k]++;
    sum += k;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    long long sub = counts[b] * b;
    long long add = counts[b] * c;
    sum -= sub;
    sum += add;
    counts[c] += counts[b];
    counts[b] = 0;
    cout << sum << endl;
  }
}
