#include <bits/stdc++.h>
static const long long MOD_NUM = 1000000007;
template <class _T>
static void get(_T& a) {
  std::cin >> a;
}
template <class _T>
static void get(_T& a, _T& b) {
  std::cin >> a >> b;
}
template <class _T>
static void get(_T& a, _T& b, _T& c) {
  std::cin >> a >> b >> c;
}
static void exec();
int main() {
  exec();
  fflush(stdout);
  return 0;
}
static void exec() {
  int N, Q;
  get(N);
  long long sum = 0;
  std::map<int, int> ai;
  for (int i = 0; i < N; i++) {
    int a;
    get(a);
    ai[a]++;
    sum += a;
  }
  get(Q);
  for (int i = 0; i < Q; i++) {
    int b, c;
    get(b, c);
    long long diff = b * ai[b];
    long long plus = c * ai[b];
    ai[c] += ai[b];
    ai[b] = 0;
    sum = sum - diff + plus;
    printf("%lld\n", sum);
  }
}
