#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int q;
  vector<int> a;
  int b[100005];
  int c[100005];
  int x;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    a.push_back(x);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    sort(a.begin(), a.end());
    auto iter1 = lower_bound(a.begin(), a.end(), b[i]);
    auto iter2 = upper_bound(a.begin(), a.end(), b[i]);
    long k = (iter2 - a.begin()) - (iter1 - a.begin());
    for (auto i = iter1 - a.begin(); i < iter2 - a.begin(); i++) {
      a[i] = c[i];
    }
    sum = sum + k * (c[i] - b[i]);
    cout << sum << endl;
  }
}
