#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, Q, A[10005], B[10005], C[10005], count[10005], ans, sum = 0;
  scanf("%d", &N);
  for (int i = 0; i <= N - 1; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i <= N - 1; i++) {
    count[A[i]]++;
  }
  scanf("%d", &Q);
  for (int i = 0; i <= Q - 1; i++) {
    scanf("%d%d", &B[i], C[i]);
  }
  for (int i = 0; i <= Q - 1; i++) {
    ans = sum - B[i] * count[B[i]] + C[i] * count[C[i]];
    printf("%d\n", ans);
  }
}
