#include <bits/stdc++.h>
const int mod = 998244353;
const int inf = 2e9;
const long long linf = 2e18;
using namespace std;
const int maxn = 2e6 + 15;
map<pair<int, int>, int> mp;
int a[maxn];
int v[maxn];
int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; n >= i; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; q >= i; i++) {
    int s, t, u;
    scanf("%d%d%d", &s, &t, &u);
    if (mp[pair<int, int>(s, t)] == 0) {
      if (u != 0) {
        mp[pair<int, int>(s, t)] = u;
        sum -= max(0, a[u] - v[u]);
        v[u]++;
        sum += max(0, a[u] - v[u]);
      }
    } else {
      if (u != 0) {
        int c = mp[pair<int, int>(s, t)];
        sum -= max(0, a[c] - v[c]);
        v[c]--;
        sum += max(0, a[c] - v[c]);
        mp[pair<int, int>(s, t)] = u;
        sum -= max(0, a[u] - v[u]);
        v[u]++;
        sum += max(0, a[u] - v[u]);
      } else {
        u = mp[pair<int, int>(s, t)];
        sum -= max(0, a[u] - v[u]);
        v[u]--;
        sum += max(0, a[u] - v[u]);
        mp[pair<int, int>(s, t)] = 0;
      }
    }
    printf("%lld\n", sum);
  }
  return 0;
}
