#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> counts(10000, 0);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    counts[tmp]++;
    ans += tmp;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < N; j++) {
      if (counts[b] != 0) {
        int oldCounts = counts[b];
        counts[c] += oldCounts;
        counts[b] = 0;
        ans -= oldCounts * b;
        ans += oldCounts * c;
      }
    }
    cout << ans << endl;
  }
}
