#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q;
int arr[N], cur[N];
map<pair<int, int>, int> qs;
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    sum += arr[i];
  }
  scanf("%d", &q);
  long long ans = 0;
  while (q--) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    if (qs[{x, y}]) {
      int a = qs[{x, y}];
      ans -= min(arr[a], cur[a]);
      cur[qs[{x, y}]]--;
      ans += min(arr[a], cur[a]);
    }
    if (z) {
      qs[{x, y}] = z;
      ans -= min(arr[z], cur[z]);
      cur[z]++;
      ans += min(arr[z], cur[z]);
    } else
      qs[{x, y}] = 0;
    printf("%lld\n", sum - ans);
  }
}
