#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    int n;
    cin >> n;
    vector<long long> in(n + 1), cnt(n + 1, 0);
    map<pair<long long, long long>, long long> ma;
    for (int i = 1; i <= n; i++) cin >> in[i];
    long long ans = accumulate(in.begin(), in.end(), 0ll);
    int q;
    cin >> q;
    while (q--) {
      long long s, t, u;
      cin >> s >> t >> u;
      long long prev = ma[make_pair(s, t)];
      if (prev != 0) {
        if (cnt[prev] <= in[prev]) ans++;
        cnt[prev]--;
      }
      if (u != 0) {
        if (cnt[u] < in[u]) ans--;
        cnt[u]++;
      }
      ma[make_pair(s, t)] = u;
      cout << ans << endl;
    }
  }
  return 0;
}
