#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 q;
  scanf("%d", &q);
  int b[q], c[q];
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &b[i], &c[i]);
  }
  long int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  int d[n + 1];
  for (int i = 0; i <= n; i++) {
    d[i] = 0;
  }
  int tmp;
  for (int i = 0; i < n; i++) {
    tmp = a[i];
    d[tmp]++;
  }
  int before, after;
  long int s[q];
  for (int i = 0; i < q; i++) {
    before = b[i];
    after = c[i];
    if (i == 0) {
      s[0] = sum + (after - before) * d[before];
    } else {
      s[i] = s[i - 1] + (after - before) * d[before];
    }
    d[after] += d[before];
    d[before] = 0;
  }
  for (int i = 0; i < q; i++) {
    printf("%ld\n", s[i]);
  }
  return 0;
}
