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