#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  vector<long long> vc(100000, 0);
  long long total = 0;
  for (long long i = 0; i < N; i++) {
    long long A;
    cin >> A;
    vc.at(A) += 1;
    total += A;
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    long long B, C;
    cin >> B >> C;
    long long tmp_b = vc.at(B);
    total -= tmp_b * B;
    vc.at(B) = 0;
    total += C * tmp_b;
    vc.at(C) += tmp_b;
    cout << total << endl;
  }
  return 0;
}
