#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int sum = 0;
  for (int s : A) {
    sum += s;
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    int first = 0, last = N - 1;
    while (first < last) {
      int now = (first + last) / 2;
      int num = A.at(now);
      if (num == B) {
        int count = now;
        while (count > -1) {
          if (A.at(count) != B) break;
          sum -= A.at(count) - C;
          A.at(count) = C;
          count--;
        }
        count = now + 1;
        while (count < N) {
          if (A.at(count) != B) break;
          sum -= A.at(count) - C;
          A.at(count) = C;
          count++;
        }
        break;
      }
      if (num > B) {
        last = now - 1;
      } else {
        first = now + 1;
      }
    }
    cout << sum << endl;
  }
}
