#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int N, Q, p[100010], b[100010], c[10010];
ll sum;
int main() {
  scanf("%d", &N);
  for (ll i = 0; i < ll(N); i++) {
    int tmp;
    scanf("%d", &tmp);
    p[tmp]++;
    sum += tmp;
  }
  scanf("%d", &Q);
  for (ll i = 0; i < ll(Q); i++) scanf("%d%d", &b[i], &c[i]);
  for (ll i = 0; i < ll(Q); i++) {
    int _b = b[i], _c = c[i];
    sum -= p[_b] * _b;
    sum += p[_b] * _c;
    p[_c] += p[_b];
    p[_b] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
