#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
long long n, q, a[MAXN], tot[MAXN], ans;
map<pair<long long, long long>, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long s, t, u;
    cin >> s >> t >> u;
    if (mp[make_pair(s, t)]) {
      if (tot[mp[make_pair(s, t)]] <= a[mp[make_pair(s, t)]]) ans++;
      tot[mp[make_pair(s, t)]]--;
    }
    mp[make_pair(s, t)] = u;
    if (tot[u] < a[u]) ans--;
    tot[u]++;
    cout << ans << endl;
  }
  return 0;
}
