#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  int Q, Bi, Ci;
  cin >> Q;
  ll asum = 0;
  for (int i = 0; i < (N); ++i) asum += A[i];
  int l, r;
  for (int qi = 0; qi < (Q); ++qi) {
    cin >> Bi >> Ci;
    sort(A.begin(), A.end());
    l = lower_bound(A.begin(), A.end(), Bi) - A.begin();
    r = upper_bound(A.begin(), A.end(), Bi) - A.begin();
    for (int i = l; i < r; ++i) A[i] = Ci;
    asum += (Ci - Bi) * (r - l);
    cout << asum << endl;
  }
  return 0;
}
