#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    int co;
    co = count(a.begin(), a.end(), b);
    int sum;
    sum = accumulate(a.begin(), a.end(), 0);
    sum = co * (c - b) + sum;
    cout << sum << endl;
    auto itr = find(a.begin(), a.end(), b);
    if (itr != a.end()) {
      auto itrs = itr - a.begin();
      fill(a.begin() + itrs, a.begin() + itrs + co, c);
    }
  }
  return 0;
}
