#include <bits/stdc++.h>
void replace(int *K, int B, int C, long double *sum) {
  *(K + C) = *(K + B) + *(K + C);
  *sum = *sum + *(K + B) * C - *(K + B) * B;
  *(K + B) = 0;
}
int main() {
  int N, A[100000], Q, B[100000], C[100000];
  int K[100000];
  long double sum = 0;
  for (int i = 0; i < 100000; i++) {
    K[i] = 0;
  }
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    K[A[i]]++;
    sum = sum + A[i];
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d", &B[i]);
    scanf("%d", &C[i]);
  }
  for (int i = 0; i < Q; i++) {
    replace(K, B[i], C[i], &sum);
    printf("%d\n", sum);
  }
  return 0;
}
