#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
int main() {
  int n, q;
  scanf("%d", &n);
  long long int a[n], sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  unordered_map<pair<int, int>, int, hash_pair> m;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int s, t, u;
    scanf("%d %d %d", &s, &t, &u);
    int f = m[make_pair(s, t)];
    if (f != 0) {
      a[f - 1]++;
      if (a[f - 1] > 0) sum++;
    }
    if (u != 0) {
      a[u - 1]--;
      if (a[u - 1] >= 0) sum--;
    }
    m[make_pair(s, t)] = u;
    cout << sum << endl;
  }
}
