#include <bits/stdc++.h>
int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
int main() {
  int N = IN(), i = 0, A, B, C, Q, count[100000] = {};
  long long sum = 0;
  memset(count, 0x00, sizeof(count));
  while (i < N) {
    A = IN();
    count[A - 1]++;
    sum += A;
    i++;
  }
  Q = IN();
  i = 0;
  while (i < Q) {
    B = IN(), C = IN();
    sum -= count[B - 1] * B;
    sum += count[B - 1] * C;
    count[C - 1] += count[B - 1];
    count[B - 1] = 0;
    printf("%lld\n", sum);
    i++;
  }
}
