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