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