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