#include <bits/stdc++.h>
using namespace std;
map<long long, int> Hash;
map<long long, int>::iterator I;
int a[200001];
int b[200001];
int Q, n, i, j, k, l, s, t, u;
long long ans;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
  scanf("%d", &Q);
  for (; Q; --Q) {
    scanf("%d%d%d", &s, &t, &u);
    I = Hash.find(1ll * s * 10000000000ll + t);
    if (I != Hash.end()) {
      ans -=
          (a[I->second] - b[I->second] > 0 ? a[I->second] - b[I->second] : 0);
      --b[I->second];
      ans +=
          (a[I->second] - b[I->second] > 0 ? a[I->second] - b[I->second] : 0);
      Hash.erase(I);
    }
    Hash.insert(pair<long long, int>(1ll * s * 10000000000ll + t, u));
    ans -= (a[u] - b[u] > 0 ? a[u] - b[u] : 0);
    ++b[u];
    ans += (a[u] - b[u] > 0 ? a[u] - b[u] : 0);
    printf("%I64d\n", ans);
  }
}
