#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, sum = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n);
  cin >> m;
  int arr2[2][m];
  for (int i = 0, r = -1, l = 1; i < m; i++, l = 1, r = -1) {
    cin >> arr2[0][i] >> arr2[1][i];
    for (int j = 0; j < n; j++) {
      if (arr[j] == arr2[0][i]) {
        r = j;
        for (int g = j + 1; g < n; g++) {
          if (arr[g] != arr2[0][i]) {
            break;
          }
          l++;
        }
        break;
      }
    }
    if (r == -1) {
      cout << sum << endl;
      continue;
    }
    sum = sum - (arr[r] * l) + arr2[1][i] * l;
    cout << sum;
    if (i != m - 1) {
      cout << endl;
    }
    if (arr2[0][i] < arr2[1][i]) {
      int j = r + l;
      for (; j < n; j++) {
        if (arr[j] >= arr2[1][i]) {
          break;
        }
        arr[j - l] = arr[j];
      }
      for (r = j - 1; l > 0; r--, l--) {
        arr[r] = arr2[1][i];
      }
    } else {
      r--;
      int j = r;
      for (; j >= 0; j--) {
        if (arr2[1][i] <= arr[j]) {
          break;
        }
        arr[j] = arr[j + l];
      }
      for (r = j + 1; l > 0; l--, r++) {
        arr[r] = arr2[1][i];
      }
    }
  }
  return 0;
}
