#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  int q;
  cin >> q;
  vector<int> B(q), C(q);
  for (int i = 0; i < q; i++) cin >> B.at(i) >> C.at(i);
  ll s = 0;
  for (int i = 0; i < n; i++) s += A.at(i);
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (A.at(j) == B.at(i)) {
        s = s - A.at(j) + C.at(i);
        A.at(j) = C.at(i);
      } else if (A.at(j) > B.at(i))
        break;
    }
    cout << s << endl;
    sort(A.begin(), A.end());
  }
  return 0;
}
