#include <bits/stdc++.h>
using namespace std;
int a[200005], cnt[200005];
map<pair<int, int>, int> mp;
int main() {
  int n, T, s, t, u;
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), ans += a[i];
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d %d", &s, &t, &u);
    pair<int, int> p{s, t};
    if (mp[p] && --cnt[mp[p]] < a[mp[p]]) ++ans;
    mp[p] = u;
    if (u && ++cnt[u] <= a[u]) --ans;
    printf("%lld\n", ans);
  }
  return 0;
}
