#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 10;
map<pair<int, int>, int> M;
long long sum[maxn << 2], msum[maxn << 2];
int a[maxn];
void pushup(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; }
void build(int rt, int l, int r) {
  if (l == r) {
    sum[rt] = a[l];
    return;
  }
  int mid = l + r >> 1;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int pos, int val) {
  if (l == r) {
    a[l] += val;
    sum[rt] = max(a[l], 0);
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    update((rt << 1), l, mid, pos, val);
  else
    update((rt << 1 | 1), mid + 1, r, pos, val);
  pushup(rt);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int s, t, u;
    scanf("%d%d%d", &s, &t, &u);
    if (u) update(1, 1, n, u, -1);
    if (M.find(make_pair(s, t)) != M.end())
      update(1, 1, n, M[make_pair(s, t)], 1);
    if (u)
      M[make_pair(s, t)] = u;
    else
      M.erase(make_pair(s, t));
    printf("%I64d\n", sum[1]);
  }
  return 0;
}
