#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, s, t, u, q, ans = 0;
  cin >> n;
  vector<long long> a(n + 1), g(n + 1, 0);
  map<pair<int, int>, int> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ans += a[i];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t >> u;
    const pair<int, int> p = {s, t};
    auto it = m.find(p);
    if (it != m.end()) {
      const int u1 = it->second;
      if (--g[u1] < a[u1]) ++ans;
      if (u == 0) m.erase(it);
    }
    if (u != 0) {
      m[p] = u;
      if (++g[u] <= a[u]) --ans;
    }
    cout << ans << '\n';
  }
  return 0;
}
