#include <iostream>
#include <vector>
using namespace std;


using VI = vector<int>;
using VVI = vector<VI>;


bool es_Monge(const VVI& M);


int main() {
  int n, m;
  while (cin >> n >> m) {
    VVI M(n, VI(m));
    for (int i = 0; i < n; ++i)
      for (int& x : M[i]) cin >> x;
    cout << es_Monge(M) << endl;

    int q;
    cin >> q;
    while (q--) {
      int i, j, x;
      cin >> i >> j >> x;
      int ant = M[i][j];
      M[i][j] = x;
      cout << es_Monge(M) << endl;
      M[i][j] = ant;
    }
    cout << string(4, '-') << endl;
  }

  return 0;
}
