#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long a[n];
  long long cnt[100012] = {};
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    long long sum = 0;
    for (long long i = 0; i < 100012; i++) {
      sum += (cnt[i] * i);
    }
    cout << sum << endl;
  }
}
