#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long ans = 0;
  vector<int> A(N);
  for (int n = 0; n < N; ++n) {
    cin >> A[n];
    ans += A[n];
  }
  int Q;
  cin >> Q;
  vector<long long> B(Q);
  vector<long long> C(Q);
  for (int n = 0; n < Q; ++n) {
    cin >> B[n] >> C[n];
  }
  vector<long long> X(10001);
  for (int n = 0; n < N; ++n) {
    X[A[n]]++;
  }
  for (int n = 0; n < Q; ++n) {
    ans = ans + C[n] * X[B[n]] - B[n] * X[B[n]];
    X[C[n]] += X[B[n]];
    X[B[n]] = 0;
    cout << ans << endl;
  }
  return 0;
}
