#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, s = 0;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    s += x[i];
  }
  sort(x, x + n);
  cin >> q;
  int z[q], y[q], t[q];
  for (int i = 0; i < q; i++) {
    t[i] = 0;
    cin >> z[i] >> y[i];
    for (int j = 0; j < n; j++) {
      if (x[j] == z[i]) t[i]++;
    }
    for (int j = i - 1; j > 0; j--) {
      if (z[i] == y[j]) {
        t[i] += t[j];
        j = 0;
      }
    }
    for (int j = i - 1; j > 0; j--) {
      if (y[i] != z[j])
        if (y[i] == y[j]) {
          t[i] += t[j];
          j = 0;
        } else
          j = 0;
    }
  }
  for (int i = 0; i < q; i++) {
    s += (y[i] - z[i]) * t[i];
    cout << s << endl;
  }
  return 0;
}
