#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k;
  cin >> n;
  long long freq[100005] = {0};
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    sum += k;
    freq[k]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long remove, add;
    remove = b * freq[b];
    add = c * freq[b];
    freq[c] += freq[b];
    sum = sum - remove + add;
    cout << sum << "\n";
  }
}
