#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, val, sum = 0;
  cin >> N;
  vector<long long> cnt(1e5 + 10, 0);
  for (int i = 0; i < N; i++) {
    cin >> val;
    cnt[val]++;
    sum += val;
  }
  long long Q, b, c;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b;
    cin >> c;
    if (cnt[b] > 0) {
      cnt[c] += cnt[b];
      cnt[b] = 0;
    }
    cout << sum << '\n';
  }
}
