#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1 << 18;
int n;
int a[N];
int cnt[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  long long ans = 0;
  for (int i = (0); i < (n); ++i) ans += a[i];
  int q;
  cin >> q;
  map<pair<int, int>, int> mp;
  while (q--) {
    int s, t, u;
    cin >> s >> t >> u;
    --s;
    --u;
    if (mp.count({s, t})) {
      int bulo = mp[make_pair(s, t)];
      ans -= max(0, a[bulo] - cnt[bulo]);
      cnt[bulo]--;
      ans += max(0, a[bulo] - cnt[bulo]);
      mp.erase({s, t});
    }
    if (u >= 0) {
      mp[make_pair(s, t)] = u;
      int bulo = u;
      ans -= max(0, a[bulo] - cnt[bulo]);
      cnt[bulo]++;
      ans += max(0, a[bulo] - cnt[bulo]);
    }
    assert(ans > 0);
    cout << ans << '\n';
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
