#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  long sum = 0;
  int a[100005] = {0};
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    a[t]++;
    sum += t;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);
    int num = a[b];
    sum -= b * num;
    sum += c * num;
    a[b] = 0;
    a[c] += num;
    printf("%ld\n", sum);
  }
  return 0;
}
