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