#include <bits/stdc++.h>
using namespace std;
uint64_t a[1000][16], b[1000][16], p63 = (1ll << 63), lastbit;
struct qs {
  int64_t t;
  int x, y;
  int order;
  int flip;
} qq[100000];
bitset<19260817> hset;
vector<int> hv;
int fsz, last;
int m, n, q;
char s01[3] = "01", ans[100000];
int hashf() {
  uint64_t r = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= fsz; ++j) {
      r = (r * 233 + a[i][j]) % 19260817;
    }
  }
  return r;
}
void grow() {
  memset(b, 0xff, sizeof(b));
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j <= fsz; ++j) {
      b[i][j] &= (a[i][j] ^ a[i - 1][j]);
      b[i - 1][j] &= (a[i][j] ^ a[i - 1][j]);
    }
  }
  for (int i = 0; i < m; ++i) {
    uint64_t bit = 1;
    b[i][0] &= (bit | (a[i][0] ^ (a[i][0] << 1)));
    bit = (a[i][0] >> 63);
    for (int j = 1; j <= fsz; ++j) {
      b[i][j] &= (a[i][j] ^ ((a[i][j] << 1) | bit));
      bit = (a[i][j] >> 63);
    }
    bit = lastbit;
    b[i][fsz] &= (bit | (a[i][fsz] ^ (a[i][fsz] >> 1)));
    bit = (a[i][fsz] << 63);
    for (int j = fsz - 1; j >= 0; --j) {
      b[i][j] &= (a[i][j] ^ ((a[i][j] >> 1) | bit));
      bit = (a[i][j] << 63);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= fsz; ++j) {
      a[i][j] ^= b[i][j];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  srand(time(0));
  cin >> m >> n >> q;
  fsz = (n - 1) / 64;
  last = (n - 1) % 64;
  lastbit = (1LL << last);
  char ch;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> ch;
      a[i][j / 64] |= ((1LL & ch) << (j % 64));
    }
  }
  for (int i = 0; i < q; ++i) {
    cin >> qq[i].x >> qq[i].y >> qq[i].t;
    --qq[i].x;
    --qq[i].y;
    qq[i].order = i;
    qq[i].flip = qq[i].t % 2;
  }
  sort(qq, qq + q, [&](const qs& a, const qs& b) { return a.t < b.t; });
  int tli = 0;
  int ringst, ringsz, findr = 0;
  for (int i = 0; tli < q; ++i) {
    if (!findr) {
      int hashv = hashf();
      if (hset.test(hashv)) {
        for (ringst = hv.size() - 1; hv[ringst] != hashv; --ringst)
          ;
        ringsz = i - ringst;
        for (int j = tli; j < q; ++j) {
          qq[j].t = (qq[j].t - i) % ringsz + i;
        }
        sort(qq + tli, qq + q,
             [&](const qs& a, const qs& b) { return a.t < b.t; });
        findr = true;
      }
      hv.push_back(hashv);
      hset.set(hashv);
    }
    while (tli < q && qq[tli].t == i) {
      int x = qq[tli].x, y = qq[tli].y;
      if ((a[x][y / 64] >> (y % 64)) & 1)
        ans[qq[tli].order] = '1' ^ qq[tli].flip;
      else
        ans[qq[tli].order] = '0' ^ qq[tli].flip;
      ++tli;
    }
    grow();
  }
  for (int i = 0; i < q; ++i) {
    putchar(ans[i]);
    putchar('\n');
  }
  fflush(stdout);
}
