#include <bits/stdc++.h>
using namespace std;
const int MOD = 1E9 + 7;
const int N = 1E5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  vector<long long> a(n);
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int qq = 1; qq <= q; qq++) {
    long long ai, bi;
    cin >> ai >> bi;
    sort(a.begin(), a.end());
    int lb = lower_bound(a.begin(), a.end(), ai) - a.begin();
    int up = upper_bound(a.begin(), a.end(), ai) - a.begin() - 1;
    for (int i = lb; i <= up; i++) a[i] = bi;
    sum = sum - (up - lb + 1) * (ai - bi);
    cout << sum << endl;
  }
}
