#include <bits/stdc++.h>
using namespace std;
int N, Q, i, sum = 0;
int A[100010];
pair<int, int> a[100010];
int main() {
  cin >> N;
  for (i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    sum += A[i];
  }
  cin >> Q;
  sort(A + 1, A + N + 1);
  for (i = 1; i <= Q; i++) {
    cin >> a[i].first;
    cin >> a[i].second;
  }
  int cx = 0;
  for (int j = 1; j <= Q; j++) {
    for (i = 1; i <= N; i++) {
      if (A[i] == a[j].first) {
        cx++;
      }
      int change = abs(a[i].first - a[i].second);
      sum += change * cx;
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}
