#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::vector<int> cnt(100001, 0);
  long long total = 0;
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
    cnt[A[i]]++;
    total += A[i];
  }
  int Q;
  std::cin >> Q;
  std::vector<int> B(N);
  std::vector<int> C(N);
  for (int i = 0; i < Q; i++) {
    std::cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    int cnt_tmp = cnt[B[i]];
    long long chg = (C[i] - B[i]) * cnt_tmp;
    total += chg;
    cnt[B[i]] = 0;
    cnt[C[i]] += cnt_tmp;
    std::cout << total << std::endl;
  }
  return 0;
}
