#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, Q, B, C;
  cin >> N;
  vector<int> A_count(pow(10, 5));
  for (int i = 0; i < N; i++) {
    cin >> a;
    A_count[a - 1]++;
  }
  int ans = 0;
  for (int j = 0; j < int(A_count.size()); j++) {
    ans += (j + 1) * A_count[j];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    if (A_count[B - 1] != 0) {
      ans += (C - B) * A_count[B - 1];
      A_count[C - 1] += A_count[B - 1];
      A_count[B - 1] = 0;
    }
    cout << ans << endl;
  }
}
