#include <bits/stdc++.h>
int n, q, times[100001];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    ans += x;
    ++times[x];
  }
  scanf("%d", &q);
  for (int i = 1, b, c; i <= q; ++i) {
    scanf("%d %d", &b, &c);
    ans -= times[b] * b;
    ans += times[b] * c;
    printf("%lld\n", ans);
    times[c] += times[b];
    times[b] = 0;
  }
  return 0;
}
