#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long n, ans = 0;
  cin >> n;
  vector<int> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    ans += v[i];
  }
  map<pair<long long, long long>, long long> mp;
  vector<long long> req(n, 0);
  long long q;
  cin >> q;
  while (q--) {
    int s, t, u;
    cin >> s >> t >> u;
    s--, u--;
    if (u == -1) {
      if (mp.find({s, t}) != mp.end()) {
        if (req[mp[{s, t}]] <= v[mp[{s, t}]]) ans++;
        req[mp[{s, t}]]--;
        mp.erase(mp.find({s, t}));
      }
      cout << ans << endl;
      continue;
    }
    if (mp.find({s, t}) != mp.end()) {
      if (req[mp[{s, t}]] <= v[mp[{s, t}]]) ans++;
      req[mp[{s, t}]]--;
    }
    mp[{s, t}] = u;
    req[u]++;
    if (req[u] <= v[u]) ans--;
    cout << max(1ll, ans) << endl;
  }
  return 0;
}
