#include <bits/stdc++.h>
using namespace std;
int n, t, b, c, s;
const int sz = 1e5;
int num[sz];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    s += num[i];
  }
  sort(num, num + n);
  cin >> t;
  while (t--) {
    cin >> b >> c;
    for (int& i : num) {
      if (i == b) {
        i = c;
        s += c - b;
        continue;
      }
      if (i > b) break;
    }
    sort(num, num + n);
    cout << s << '\n';
  }
  return 0;
}
