#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n + 1, 0);
  vector<long long int> cnt(n + 1, 0);
  map<pair<long long int, long long int>, long long int> mp;
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long int q;
  cin >> q;
  for (long long int i = 0, s, t, u; i < q; i++) {
    cin >> s >> t >> u;
    auto it = mp.find({s, t});
    if (it != mp.end()) {
      if (cnt[it->second] > a[it->second]) {
        sum--;
      }
      cnt[it->second]--;
      mp.erase(it);
    }
    if (u >= 1) {
      mp[make_pair(s, t)] = u;
      cnt[u]++;
      if (cnt[u] > a[u]) {
        sum++;
      }
    }
    cout << sum - mp.size() << "\n";
  }
  return 0;
}
