#include <bits/stdc++.h>
using namespace std;
int N, Q;
vector<int> a;
vector<pair<int, int>> b;
int main() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  cin >> Q;
  b.resize(Q);
  for (int i = 0; i < Q; i++) cin >> b[i].first >> b[i].second;
  sort(a.begin(), a.end());
  for (int i = 0; i < Q; i++) {
    auto iter = lower_bound(a.begin(), a.end(), b[i].first);
    auto border = lower_bound(a.begin(), a.end(), b[i].second);
    while (*iter == b[i].first) {
      *iter = 0;
      a.insert(border - 1, b[i].second);
      iter++;
    }
    cout << accumulate(a.begin(), a.end(), 0) << endl;
  }
}
