#include <bits/stdc++.h>
int main() {
  int n, count[1 << 6] = {0}, p, q, b[1 << 6] = {0}, c[1 << 6] = {0};
  long int sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    count[p]++;
    sum = sum + p;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &b[i], &c[i]);
    sum = sum + (c[i] - b[i]) * count[b[i]];
    printf("%d\n", sum);
    count[c[i]] = count[c[i]] + count[b[i]];
    count[b[i]] = 0;
  }
}
