#include <bits/stdc++.h>
using namespace std;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
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;
}
const long long INF = 1LL << 60;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += a[i];
  int q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sort(a.begin(), a.end());
    int lb, rb;
    int l = -1, r = n;
    while (r - l > 1) {
      int m = l + (r - l) / 2;
      if (a[m] < b)
        l = m;
      else
        r = m;
    }
    lb = l + 1;
    l = -1, r = n;
    while (r - l > 1) {
      int m = l + (r - l) / 2;
      if (b < a[m])
        r = m;
      else
        l = m;
    }
    rb = r;
    for (long long i = lb; i < rb; i++) a[i] = c;
    sum += (c - b) * (rb - lb);
    cout << sum << endl;
  }
}
