#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (int)(q); i++) {
    cin >> b[i] >> c[i];
  }
  sort(a.begin(), a.end());
  vector<int> what(1, a[0]);
  vector<int> kosu(1, 0);
  int temp = a[0];
  for (int i = (1); i < (int)(n); i++) {
    if (temp == a[i]) {
      kosu.end()++;
    } else {
      temp = a[i];
      what.push_back(a[i]);
      kosu.push_back(0);
    }
  }
  for (int i = 0; i < (int)(q); i++) {
    for (int j = 0; j < (int)(what.size()); j++) {
      if (b[i] == what[j]) {
        sum += kosu[j] * (c[i] - b[i]);
      }
    }
    cout << sum << endl;
  }
}
