#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], sum[N];
map<pair<int, int>, int> Map;
int main() {
  int n, m;
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int s, t, u;
    scanf("%d%d%d", &s, &t, &u);
    if (Map.find(make_pair(s, t)) != Map.end()) {
      int u1 = Map[make_pair(s, t)];
      sum[u1]--;
      if (sum[u1] < a[u1]) ans++;
    }
    Map[make_pair(s, t)] = u;
    if (sum[u] < a[u]) ans--;
    sum[u]++;
    printf("%lld\n", ans);
  }
}
