#include <bits/stdc++.h>
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int N;
  std::cin >> N;
  uint64_t sum = 0;
  std::array<int, 100001> A;
  for (int i = 0; i != N; i++) {
    int a;
    std::cin >> a;
    sum += a;
    A[a]++;
  }
  int Q;
  std::cin >> Q;
  int B, C;
  for (int i = 0; i != Q; i++) {
    std::cin >> B >> C;
    sum = sum + (C - B) * A[B];
    A[C] = A[C] + A[B];
    A[B] = 0;
    std::cout << sum << "\n";
  }
  std::cout << std::endl;
  return 0;
}
