#include <bits/stdc++.h>
int main() {
  int N, Q;
  std::cin >> N;
  int* A = new int[N];
  int dic[100000] = {};
  int i, j;
  for (i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::cin >> Q;
  int* B = new int[Q];
  int* C = new int[Q];
  for (i = 0; i < Q; i++) {
    std::cin >> B[i] >> C[i];
  }
  int count = 0;
  for (i = 0; i < N; i++) {
    dic[A[i]] += 1;
    count = count + A[i];
  }
  int tmp;
  for (i = 0; i < Q; i++) {
    tmp = dic[B[i]];
    dic[B[i]] = 0;
    dic[C[i]] += tmp;
    count += tmp * (C[i] - B[i]);
    std::cout << count << std::endl;
  }
  delete[] A;
  delete[] B;
  delete[] C;
  return 0;
}
