#include <bits/stdc++.h>
using ll = long long;
int main() {
  int N;
  scanf("%d", &N);
  static ll dat[100001];
  for (int i = 0; i < N; i++) {
    int A;
    scanf("%lld", &A);
    dat[A]++;
  }
  ll ans = 0;
  for (int k = 1; k <= 100000; k++) {
    ans += k * dat[k];
  }
  int Q;
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    int B, C;
    scanf("%d%d", &B, &C);
    ll diff = dat[B] * (C - B);
    ans += diff;
    dat[C] += dat[B];
    dat[B] = 0;
    printf("%lld\n", ans);
  }
  return 0;
}
