#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
map<pair<int, int>, int> mp;
int n, a[N], b[N];
long long res;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    res += a[i];
  }
  int T;
  cin >> T;
  while (T--) {
    int u, v, c;
    cin >> u >> v >> c;
    if (mp.count({u, v})) {
      int t = mp[{u, v}];
      b[t]--;
      if (a[t] - b[t] >= 1) res++;
      mp.erase({u, v});
    }
    if (c != 0) {
      b[c]++;
      if (a[c] - b[c] >= 0) res--;
      mp[{u, v}] = c;
    }
    cout << res << endl;
  }
  return 0;
}
