#include <bits/stdc++.h>
using namespace std;
template <class T>
bool INRANGE(T x, T a, T b) {
  return a <= x && x <= b;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < (N); ++i) cin >> a[i];
  sort((a).begin(), (a).end());
  int Q;
  cin >> Q;
  vector<pair<int, int> > bc(Q);
  for (int i = 0; i < (Q); ++i) {
    int b, c;
    cin >> b >> c;
    bc[i] = pair<int, int>(b, c);
  }
  long long ans = accumulate((a).begin(), (a).end(), 0);
  map<int, int> cnt;
  for (int i = 0; i < (Q); ++i) {
    int dif = bc[i].second - bc[i].first;
    int num =
        distance(a.begin(),
                 lower_bound((a).begin(), (a).end(), bc[i].first + 1)) -
        distance(a.begin(), lower_bound((a).begin(), (a).end(), bc[i].first));
    if (cnt[bc[i].first] != 0) num += cnt[bc[i].first];
    cnt[bc[i].second] += num;
    if (cnt[bc[i].first] != 0) cnt[bc[i].first] -= num;
    ans += dif * num;
    cout << ans << endl;
  }
  return 0;
}
