#include <bits/stdc++.h>
const int MAX_N = 100005;
int ans[MAX_N];
int main() {
  int64_t s = 0;
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int val;
    scanf("%d", &val);
    ans[val]++;
    s += val;
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 0; i < Q; ++i) {
    int B, C;
    scanf("%d %d", &B, &C);
    s -= ans[B] * B;
    s += ans[B] * C;
    ans[C] += ans[B];
    ans[B] = 0;
    printf("%lld\n", s);
  }
}
