#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int first;
    scanf("%d", &first);
    sum += first;
    cnt[first]++;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);
    sum -= b * cnt[b];
    sum += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    printf("%lld\n", sum);
  }
}
