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