#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 7;
int N, Q;
long long a[maxN], update[maxN];
struct hashfunc {
  template <typename T, typename U>
  size_t operator()(const pair<T, U> &i) const {
    return hash<T>()(i.first) ^ hash<U>()(i.second);
  }
};
unordered_map<pair<int, int>, int, hashfunc> mp;
pair<int, int> pir;
int main() {
  long long ans = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &a[i]);
    ans += a[i];
  }
  scanf("%d", &Q);
  int S, T, U, las_U;
  while (Q--) {
    scanf("%d%d%d", &S, &T, &U);
    pir = make_pair(S, T);
    if (!mp[pir]) {
      mp[pir] = U;
      update[U]++;
      if (update[U] <= a[U]) {
        ans--;
      }
    } else {
      las_U = mp[pir];
      update[las_U]--;
      if (update[las_U] < a[las_U]) {
        ans++;
      }
      mp[pir] = U;
      if (U) {
        update[U]++;
        if (update[U] <= a[U]) {
          ans--;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
