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