#include <bits/stdc++.h>
using namespace std;
int n;
int a[300005];
map<pair<int, int>, int> s;
int main() {
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
  int _;
  scanf("%d", &_);
  while (_--) {
    int u, v, f;
    scanf("%d%d%d", &u, &v, &f);
    if (f == 0) {
      if (s[make_pair(u, v)] != 0) {
        a[s[make_pair(u, v)]]++;
        if (a[s[make_pair(u, v)]] > 0) ans++;
        s[make_pair(u, v)] = 0;
      }
    } else {
      if (s[make_pair(u, v)] != 0) {
        a[s[make_pair(u, v)]]++;
        if (a[s[make_pair(u, v)]] > 0) ans++;
        s[make_pair(u, v)] = 0;
      }
      s[make_pair(u, v)] = f;
      a[s[make_pair(u, v)]]--;
      if (a[s[make_pair(u, v)]] >= 0) ans--;
    }
    printf("%lld\n", ans);
  }
}
