#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n + 1);
  long long turns = 0;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    turns += x;
    v[i] = x;
  }
  map<pair<long long, long long>, long long> m;
  long long q;
  cin >> q;
  vector<long long> bonus(n + 1);
  long long deduc = 0;
  for (long long i = 0; i < q; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (m.find({a, b}) != m.end()) {
      long long val = m[{a, b}];
      bonus[val]--;
      if (bonus[val] < v[val]) {
        deduc--;
      }
      if (c == 0) {
        m.erase({a, b});
      }
    }
    if (c != 0) {
      m[{a, b}] = c;
      bonus[c]++;
      if (bonus[c] <= v[c]) {
        deduc++;
      }
    }
    cout << turns - deduc << '\n';
  }
}
