#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long n, m, ans = 0;
  cin >> n;
  vector<long long> ned(n + 1);
  map<pair<long long, long long>, long long> zap;
  ned[0] = -1;
  for (long long i = 0; i < n; ++i) {
    cin >> ned[i + 1];
    ans += ned[i + 1];
  }
  cin >> m;
  for (long long i = 0; i < m; ++i) {
    long long a, b, next;
    cin >> a >> b >> next;
    if (zap.find({a, b}) != zap.end()) {
      long long pred = zap[{a, b}];
      if (pred != 0) ned[pred]++;
      if (ned[pred] > 0) ++ans;
      if (next == 0)
        zap.erase({a, b});
      else {
        zap[{a, b}] = next;
        ned[next]--;
        if (ned[next] >= 0) --ans;
      }
    } else {
      zap[{a, b}] = next;
      ned[next]--;
      if (ned[next] >= 0) --ans;
    }
    cout << ans << endl;
  }
}
