#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  static int A[100000];
  static int B[100000];
  static int C[100000];
  static long long S[100000];
  int tempA;
  for (int i = 0; i < N; i++) {
    cin >> tempA;
    tempA--;
    A[tempA]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    int tempB = A[B[i] - 1];
    A[B[i] - 1] = 0;
    A[C[i] - 1] += tempB;
    long long sum = 0;
    for (int j = 0; j < N; j++) {
      sum += (long long)A[j] * (long long)(j + 1);
    }
    printf("%lld", sum);
  }
  return 0;
}
