#include <bits/stdc++.h>
int n, q, hv[200000 + 1], a[200000 + 1];
long long sum;
std::map<std::pair<int, int>, int> mp;
void inc(int c) {
  hv[c]++;
  if (hv[c] <= a[c]) sum--;
}
void dec(int c) {
  hv[c]--;
  if (hv[c] < a[c]) sum++;
}
void run() {
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    hv[i] = 0;
    sum += a[i];
  }
  std::cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v, c;
    std::cin >> u >> v >> c;
    std::map<std::pair<int, int>, int>::iterator it =
        mp.find(std::pair<int, int>(u, v));
    if (it == mp.end()) {
      if (c != 0) {
        mp.insert(
            std::pair<std::pair<int, int>, int>(std::pair<int, int>(u, v), c));
        inc(c);
      }
    } else {
      dec(it->second);
      if (c == 0)
        mp.erase(it);
      else {
        it->second = c;
        inc(c);
      }
    }
    std::cout << sum << '\n';
  }
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  run();
  return 0;
}
