#include <bits/stdc++.h>
using namespace std;
bool compare(long long int a, long long int b) { return a > b; }
struct pair_hash {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &pair) const {
    return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> a(n + 1);
  long long int sum = 0;
  for (long long int i = 1; i < n + 1; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long int q;
  cin >> q;
  vector<long long int> b(n + 1, 0);
  map<pair<long long int, long long int>, long long int> m;
  for (long long int i = 0; i < q; i++) {
    long long int s, t, u;
    cin >> s >> t >> u;
    if (m.find(make_pair(s, t)) == m.end()) {
      m[make_pair(s, t)] = u;
      b[u]++;
      if (u != 0 && b[u] <= a[u]) sum--;
    } else {
      long long int v = m[make_pair(s, t)];
      b[v]--;
      if (b[v] < a[v]) sum++;
      m[make_pair(s, t)] = u;
      b[u]++;
      if (u != 0 && b[u] <= a[u]) sum--;
    }
    cout << sum << "\n";
  }
}
