#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> AA(1e5 + 10, 0);
  long long ans = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> A[i];
    AA[A[i]]++;
    ans += A[i];
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q);
  vector<long long> C(Q);
  for (long long i = 0; i < (long long)(Q); i++) {
    cin >> B[i] >> C[i];
  }
  for (long long i = 0; i < (long long)(Q); i++) {
    if (AA[B[i]] == 0) continue;
    ans -= AA[B[i]] * B[i];
    AA[C[i]] += AA[B[i]];
    ans += AA[C[i]] * C[i];
    AA[B[i]] = 0;
    cout << ans << endl;
  }
}
