#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<long long, long long> make_pair;
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < (n); i++) {
    int first;
    cin >> first;
    make_pair[first]++;
    sum += first;
  }
  int tx;
  cin >> tx;
  for (int i = 0; i < (tx); i++) {
    long long a, b;
    cin >> a >> b;
    long long freq =
        make_pair.find(a) == make_pair.end() ? 0 : make_pair.find(a)->second;
    long long freqt =
        make_pair.find(b) == make_pair.end() ? 0 : make_pair.find(b)->second;
    sum -= (a * freq);
    make_pair[a] = 0;
    make_pair[b] = freq + freqt;
    sum += freq * b;
    cout << sum << endl;
  }
  return 0;
}
