#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
int n, m, a[N], x[N], y[N], z[N], cnt[N];
long long ans;
map<pair<int, int>, int> s;
template <typename T>
inline T read() {
  T x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * w;
}
int main() {
  n = read<int>();
  for (int i = 1; i <= n; i++) ans += a[i] = read<int>();
  m = read<int>();
  int tmp;
  for (int i = 1; i <= m; i++) {
    x[i] = read<int>(), y[i] = read<int>(), z[i] = read<int>();
    if (s[make_pair(x[i], y[i])])
      tmp = s[make_pair(x[i], y[i])], ans += cnt[z[tmp]] <= a[z[tmp]],
      cnt[z[tmp]]--, s[make_pair(x[i], y[i])] = 0;
    if (!z[i]) {
      printf("%lld\n", ans);
      continue;
    }
    s[make_pair(x[i], y[i])] = i, ans -= cnt[z[i]] < a[z[i]], cnt[z[i]]++;
    printf("%lld\n", ans);
  }
  return 0;
}
