#include <bits/stdc++.h>
using namespace std;
const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 11;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 7;
const double long rf = 1e-14;
int n, q;
int a[N];
long long t[4 * N];
map<int, int> ch[N];
void build(int x, int l, int r) {
  if (l == r) {
    t[x] = a[l];
    return;
  }
  int m = (l + r) / 2;
  build(x * 2, l, m);
  build(x * 2 + 1, m + 1, r);
  t[x] = t[x + x] + t[x + x + 1];
}
void upd(int x, int l, int r, int p, int val) {
  if (l == r) {
    t[x] += val;
    return;
  }
  int m = (l + r) / 2;
  if (p <= m)
    upd(x * 2, l, m, p, val);
  else
    upd(x * 2 + 1, m + 1, r, p, val);
  t[x] = max(0ll, t[x + x]) + max(0ll, t[x + x + 1]);
}
void solve1() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  cin >> q;
  while (q--) {
    int s, t1, u;
    cin >> s >> t1 >> u;
    if (ch[s].find(t1) != ch[s].end()) {
      upd(1, 1, n, ch[s][t1], 1);
    }
    if (!u)
      ch[s].erase(t1);
    else {
      ch[s][t1] = u;
      upd(1, 1, n, u, -1);
    }
    cout << t[1] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int cghf = 1;
  while (cghf--) {
    solve1();
  }
}
