#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  long long a[100002];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        if (b > c)
          sum -= a[i] - c;
        else
          sum += c - a[i];
        a[i] = c;
      }
    }
    cout << sum << endl;
  }
}
