#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  vector<int> a(n);
  long long stSum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    stSum += a[i];
  }
  sort(a.begin(), a.end());
  int q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    auto result = find(a.begin(), a.end(), b);
    if (result != a.end()) {
      stSum += c - b;
      a[*result] = c;
    }
    cout << stSum << endl;
  }
}
