#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  unordered_map<int64_t, int> A;
  int64_t SUM = 0;
  for (int i = 0; i < (N); i++) {
    int64_t a;
    cin >> a;
    A[a]++;
    SUM += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); i++) {
    int B, C;
    cin >> B >> C;
    if (A.count(B)) {
      int cnt = A[B];
      SUM -= B * cnt;
      SUM += C * cnt;
      A.erase(B);
      A[C] += cnt;
    }
    cout << SUM << endl;
  }
  return 0;
}
