#include <bits/stdc++.h>
int W_Length(char *str) {
  int length = 0;
  while (*str++ != '\0') length++;
  return length;
}
double deg(double theta) { return theta * (2 * 3.14159265359) / 360; }
int cmp(const void *p, const void *q) { return *(int *)p - *(int *)q; }
int cmp_s(const void *left, const void *right) {
  char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
int main(void) {
  int x, a[210000] = {0}, n, temp, q, b, c, i;
  long long int sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &temp);
    a[temp] += 1;
  }
  for (i = 0; i <= 100000; i++) {
    sum += i * a[i];
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d%d", &b, &c);
    sum = sum + c * a[b] - b * a[b];
    a[c] = a[c] + a[b];
    a[b] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
