#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, q, x, y, z;
  cin >> n;
  long long a[n + 1], val[n + 1], i, ans = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    val[i] = 0;
    ans += a[i];
  }
  map<pair<long long, long long>, long long> mp;
  cin >> q;
  while (q--) {
    cin >> x >> y >> z;
    if (mp[{x, y}]) {
      val[mp[{x, y}]]--;
      if (val[mp[{x, y}]] < a[mp[{x, y}]]) ans++;
    }
    mp[{x, y}] = z;
    if (z) {
      val[z]++;
      if (val[z] <= a[z]) ans--;
    }
    cout << ans << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
