#include <bits/stdc++.h>
int main(void) {
  int n;
  int list[100005];
  scanf("%d", &n);
  int in;
  long sum = 0;
  for (int i = 0; i < 100001; list[i++] = 0)
    ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &in);
    list[in]++;
    sum += in;
  }
  int q;
  scanf("%d", &q);
  int to;
  int from;
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &from, &to);
    sum += (to - from) * list[from];
    printf("%ld\n", sum);
  }
  return 0;
}
