#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, sum = 0;
  cin >> n;
  vector<long long> arr(n + 1);
  for (long long i = 1; i <= n; i++) cin >> arr[i], sum += arr[i];
  map<pair<long long, long long>, long long> ma;
  long long m, a, b, c;
  cin >> m;
  while (m--) {
    cin >> a >> b >> c;
    if (!ma.count({a, b})) {
      if (c > 0) {
        arr[c]--;
        if (arr[c] >= 0) sum--;
      }
    } else {
      long long temp = ma[{a, b}];
      arr[temp]++;
      if (arr[temp] > 0) sum++;
      if (c > 0) {
        arr[c]--;
        if (arr[c] >= 0) sum--;
      } else {
        ma.erase(ma.find({a, b}));
      }
    }
    if (c != 0) ma[{a, b}] = c;
    cout << sum << endl;
  }
  return 0;
}
