#include <bits/stdc++.h>
int A[100001];
int F[100001];
int main() {
  int N, i, Q, B, C, n;
  long long sum = 0;
  scanf("%d", &N);
  A[0] = 0;
  for (i = 1; i <= N; i++) {
    F[i] = 0;
    scanf("%d", &A[i]);
    sum += A[i];
    F[A[i]] += 1;
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d %d", &B, &C);
    F[C] += F[B];
    sum = sum + (long long)F[B] * (long long)(C - B);
    F[B] = 0;
    printf("%lld\n", sum);
  }
}
