#include <bits/stdc++.h>
int up_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int down_int(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int up_char(const void *left, const void *right) {
  return strcmp((char *)left, (char *)right);
}
int down_char(const void *left, const void *right) {
  return strcmp((char *)right, (char *)left);
}
int main() {
  long long ans = 0;
  int flag = 0;
  int i, j, n, q, a[200000], b[200000], c[200000];
  long long times[200000];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++) scanf("%d %d", &b[i], &c[i]);
  for (i = 0; i < n; i++) times[a[i]]++;
  for (i = 1; i <= n; i++) ans += (times[i] * i);
  for (i = 0; i < q; i++) {
    if (times[b[i]] * (c[i] - b[i]) != 0) {
      ans += (times[b[i]] * c[i]);
      ans -= (times[b[i]] * b[i]);
      times[c[i]] += times[b[i]];
      times[b[i]] = 0;
      printf("%lld\n", ans);
    } else {
      printf("%lld\n", ans);
    }
  }
  return 0;
}
