#include <bits/stdc++.h>
void replace(long long int *a, long long int *b) {
  *b += *a;
  *a = 0;
}
int main(void) {
  long long int n;
  scanf("%lld", &n);
  long long int num_count[100000];
  for (long long int i = 0; i < 100000; i++) {
    num_count[i] = 0;
  }
  for (long long int i = 0; i < n; i++) {
    long long int num;
    scanf(" %lld", &num);
    num_count[num - 1]++;
  }
  long long int q;
  scanf(" %lld", &q);
  for (long long int i = 0; i < q; i++) {
    long long int b, c;
    scanf(" %lld %lld", &b, &c);
    replace(&num_count[b - 1], &num_count[c - 1]);
    long long int sum = 0;
    for (long long int i = 0; i < 100000; i++) {
      sum += (i + 1) * num_count[i];
    }
    printf("%lld\n", sum);
  }
  return 0;
}
