#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
int n, a[N];
map<pair<int, int>, int> m;
long long sum;
void init() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];
}
void solve() {
  int q, s, t, u;
  cin >> q;
  while (q--) {
    cin >> s >> t >> u;
    if (u == 0) {
      auto it = m.find({s, t});
      if (it != m.end()) {
        a[it->second]++;
        if (a[it->second] > 0) sum++;
        m.erase(it);
      }
    } else {
      auto it = m.find({s, t});
      if (it != m.end()) {
        a[it->second]++;
        if (a[it->second] > 0) sum++;
        it->second = u;
        a[u]--;
        if (a[u] >= 0) sum--;
      } else {
        m[{s, t}] = u;
        a[u]--;
        if (a[u] >= 0) sum--;
      }
    }
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}
