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