#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, q;
  cin >> n;
  int sum = 0;
  vector<int> freq(100069, 0);
  for (int i = 0, inp; i < n; ++i) {
    cin >> inp;
    freq[inp]++;
    sum += inp;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= freq[b] * b;
    sum += freq[b] * c;
    freq[c] += freq[b];
    freq[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
