#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
const int mxN = 200 * 1000 + 5;
int a[mxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  int q;
  cin >> q;
  map<pair<int, int>, int> who;
  while (q--) {
    int s, t, u;
    cin >> s >> t >> u;
    pair<int, int> pp{s, t};
    if (who.count(pp)) {
      int v = who[pp];
      a[v]++;
      if (a[v] > 0) {
        ans++;
      }
      if (a[u] > 0) {
        ans--;
      }
      a[u]--;
      who[pp] = u;
    } else if (u > 0) {
      if (a[u] > 0) {
        ans--;
      }
      a[u]--;
      who[pp] = u;
    }
    cout << ans << '\n';
  }
}
