#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int sum1 = 0, a_count[100000];
  for (int i = 0; i < 100000; i++) a_count[i] = 0;
  for (int i = 0; i < n; i++) {
    a_count[a[i]] += 1;
  }
  for (int i = 0; i < n; i++) sum1 += a[i];
  int q;
  scanf("%d", &q);
  int b[q], c[q];
  for (int i = 0; i < q; i++) scanf("%d%d", &b[i], &c[i]);
  for (int i = 0; i < q; i++) {
    int henka = 0;
    henka = (c[i] - b[i]) * a_count[b[i]];
    a_count[c[i]] += a_count[b[i]];
    a_count[b[i]] = 0;
    sum1 += henka;
    printf("%d\n", sum1);
  }
}
