#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, P;
  long long sum = 0;
  cin >> N;
  vector<long long> X(99999);
  for (int i = 0; i < N; i++) {
    cin >> P;
    X.at(P - 1)++;
    sum += P;
  }
  cin >> Q;
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    sum += (C - B) * X.at(B - 1);
    cout << sum << endl;
    X.at(C - 1) += X.at(B - 1);
    X.at(B - 1) = 0;
  }
  return 0;
}
