#include <bits/stdc++.h>
struct FastIO {
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0);
  }
} fastio;
struct BIT {
  long long size;
  std::vector<long long> data;
  BIT(long long n) : data(n + 1, 0), size(n) {}
  void add(long long i, long long v) {
    i += 1;
    while (i <= size) {
      data[i] += v;
      i += i & -i;
    }
  }
  long long query(long long l, long long r) {
    long long rv = 0;
    while (r > 0) {
      rv += data[r];
      r -= r & -r;
    }
    long long lv = 0;
    while (l > 0) {
      lv += data[l];
      l -= l & -l;
    }
    return rv - lv;
  }
};
signed main() {
  long long n;
  std::cin >> n;
  std::vector<long long> goal(n);
  for (long long i = 0; i < (n); i++) std::cin >> goal[i];
  long long sum = 0;
  for (long long i = 0; i < (n); i++) sum += goal[i];
  long long q;
  std::cin >> q;
  BIT bonus(n);
  std::map<std::pair<long long, long long>, long long> map;
  std::vector<long long> excess(n, 0);
  for (long long qq = 0; qq < (q); qq++) {
    long long a, b, c;
    std::cin >> a >> b >> c;
    long long d = map[std::make_pair(a, b)];
    if (d > 0) {
      if (excess[d - 1] == 0)
        bonus.add(d - 1, -1);
      else
        excess[d - 1]--;
    }
    if (c > 0) {
      if (bonus.query(c - 1, c) < goal[c - 1])
        bonus.add(c - 1, 1);
      else
        excess[c - 1]++;
    }
    map[std::make_pair(a, b)] = c;
    std::cout << (sum - bonus.query(0, n)) << '\n';
  }
  return 0;
}
