#include <bits/stdc++.h>
int main(void) {
  int N;
  scanf("%d", &N);
  int A[100000];
  long int S = 0;
  int i, j;
  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    S += A[i];
  }
  int Q;
  scanf("%d", &Q);
  int b, c, cnt;
  for (i = 0; i < Q; i++) {
    scanf("%d %d", &b, &c);
    cnt = 0;
    for (j = 0; j < N; j++)
      if (A[j] == b) {
        A[j] = c;
        cnt++;
      }
    S += (c - b) * cnt;
    printf("%ld\n", S);
  }
  return 0;
}
