#include <bits/stdc++.h>
static const int MAX_N = 100001;
int vals[MAX_N];
using namespace std;
int main() {
  fill(vals, vals + MAX_N, 0);
  int N, s, t, Q, num;
  long long ans = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &t);
    ans += t;
    vals[t]++;
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &s, &t);
    num = vals[s], vals[s] = 0, vals[t] += num;
    ans = ans - num * s + num * t;
    printf("%lld\n", ans);
  }
  return 0;
}
