#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    sort(arr, arr + n);
    int index = lower_bound(arr, arr + n, b) - arr;
    if (index > n) {
      cout << sum << '\n';
      continue;
    }
    if (arr[index] != b) {
      cout << sum << '\n';
      continue;
    }
    int up = upper_bound(arr, arr + n, b) - arr;
    int total = (up - index) * b;
    sum -= total;
    sum += ((up - index) * c);
    for (int i = index; i < up; i++) arr[i] = c;
    cout << sum << '\n';
  }
}
