#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a[200200];
long long ans = 0;
int q;
map<pair<int, int>, int> g;
int in[200200];
void remove(int second, int t) {
  if (g[make_pair(second, t)] == second) {
    ans += min(a[second], in[second]);
    ans++;
    a[second]++;
    ans -= min(a[second], in[second]);
    g.erase(make_pair(second, t));
  } else {
    int u = g[make_pair(second, t)];
    g.erase(make_pair(second, t));
    ans += min(a[u], in[u]);
    in[u]--;
    ans -= min(a[u], in[u]);
  }
}
void add(int second, int t, int u) {
  if (u == second) {
    ans += min(a[second], in[second]);
    ans--;
    a[second]--;
    ans -= min(a[second], in[second]);
    g[make_pair(second, t)] = u;
  } else {
    ans += min(a[u], in[u]);
    in[u]++;
    ans -= min(a[u], in[u]);
    g[make_pair(second, t)] = u;
  }
}
void process() {
  int second, t, u;
  scanf("%d%d%d", &second, &t, &u);
  second--;
  u--;
  if (g.count(make_pair(second, t)) > 0) remove(second, t);
  if (u >= 0) add(second, t, u);
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    ans += a[i];
  }
  scanf("%d", &q);
  while (q--) process();
  return 0;
}
