#include <bits/stdc++.h>
#pragma GCC optimize("O2")
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(void) {
  int A, B, C, N, Q, num[100000] = {0};
  static long long sum = 0;
  N = IN();
  while (N--) {
    A = IN();
    num[A - 1]++;
    sum += A;
  }
  Q = IN();
  while (Q--) {
    B = IN() - 1;
    C = IN() - 1;
    sum += 1ll * num[B] * (C - B);
    num[C] += num[B];
    num[B] = !num[B];
    printf("%lld\n", sum);
  }
}
