#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
template <typename T1, typename T2>
inline void checkMin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void checkMax(T1& a, T2 b) {
  if (a < b) a = b;
}
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    ans += arr[i];
  }
  int q;
  cin >> q;
  vector<int> curr = arr;
  vector<map<int, int>> opa(n);
  for (int i = 0; i < q; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    if (opa[a].find(b) != opa[a].end()) {
      ++curr[opa[a][b]];
      if (curr[opa[a][b]] > 0) ++ans;
      opa[a].erase(opa[a].find(b));
    }
    if (c != 0) {
      --c;
      opa[a][b] = c;
      --curr[c];
      if (curr[c] >= 0) --ans;
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
    cout << '\n';
  }
  return 0;
}
