#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N = 1, Q;
  cin >> N;
  vector<long long> v(100001);
  v.resize(100001);
  for (long long i = 0; i < N; i++) {
    int a;
    cin >> a;
    v[a]++;
  }
  cin >> Q;
  auto Output = [&]() {
    long long sum = 0;
    for (int i = 1; i < 100001; i++) {
      sum += i * v[i];
    }
    cout << sum << endl;
  };
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b;
    cin >> c;
    v[c] += v[b];
    v[b] = 0;
    Output();
  }
  return 0;
}
