#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 5;
int n, q;
int a[maxn];
int m[maxn];
map<pair<int, int>, int> mp;
ll ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], ans += a[i];
  cin >> q;
  while (q--) {
    int s, t, u;
    cin >> s >> t >> u;
    auto p = mp.find({s, t});
    if (p != mp.end()) {
      int ps = (*p).second;
      if (m[ps] <= a[ps]) ans++;
      m[ps]--;
      mp.erase(p);
    }
    if (u) {
      if (m[u] < a[u]) ans--;
      m[u]++;
      mp[{s, t}] = u;
    }
    cout << ans << '\n';
  }
}
