#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A, A + N);
  int Q;
  cin >> Q;
  int B[Q], C[Q], d[Q];
  map<int, int> mp;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    d[i] = C[i] - B[i];
  }
  for (int i = 0; i < Q; i++) {
    mp[B[i]] += upper_bound(A, A + N, B[i]) - lower_bound(A, A + N, B[i]);
    mp[C[i]] += mp[B[i]];
    sum += mp[B[i]] * d[i];
    cout << sum << endl;
  }
}
