#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, Q;
  vector<int> A(N), B(Q), C(Q);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  cin >> Q;
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  vector<int> D(100005);
  for (int i = 1; i <= 100000; i++) D[i] = 0;
  for (int i = 0; i < N; i++) D[A[i]] += 1;
  ll sum = 0;
  for (ll i = 0; i < N; i++) sum += A[i];
  for (int q = 0; q < Q; q++) {
    sum -= B[q] * D[B[q]];
    sum += C[q] * D[B[q]];
    D[C[q]] += D[B[q]];
    D[B[q]] = 0;
    cout << sum << endl;
  }
}
