#include <bits/stdc++.h>
using namespace std;
long long a[200010], b[200010], n, q, ans;
map<pair<long long, long long>, long long> m;
void solve() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
    b[i] = a[i];
  }
  cin >> q;
  while (q--) {
    long long u, t, v;
    cin >> u >> t >> v;
    if (m[{u, t}]) {
      ans -= min(a[m[{u, t}]], max(0LL, b[m[{u, t}]]));
      b[m[{u, t}]]++;
      ans += min(a[m[{u, t}]], max(0LL, b[m[{u, t}]]));
      m[{u, t}] = 0;
    }
    if (v != 0) {
      m[{u, t}] = v;
      ans -= min(a[v], max(0LL, b[v]));
      b[v]--;
      ans += min(a[v], max(0LL, b[v]));
    }
    cout << ans << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
