#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 1 << 10;
bitset<maxN> B[2][maxN], sht[2];
map<long long, vector<pair<int, int> > > M;
char in[maxN];
int ans[maxN * maxN];
void otocz(int s, int n, int m) {
  B[s][0] = ~B[s][1];
  B[s][n + 1] = ~B[s][n];
  for (int i = (1); i < (n + 1); i++) {
    B[s][i].set(0, B[s][i][1] ^ 1);
    B[s][i].set(m + 1, B[s][i][m] ^ 1);
  }
}
void print(int s, int n, int m) {
  for (int i = (1); i < (n + 1); i++) {
    for (int j = (1); j < (m + 1); j++) printf("%d", (int)B[s][i][j]);
    printf("\n");
  }
  printf("\n=============\n\n");
}
void solve() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = (1); i < (n + 1); i++) {
    scanf("%s", in + 1);
    for (int j = (1); j < (m + 1); j++) B[0][i].set(j, in[j] - '0');
  }
  otocz(0, n, m);
  for (int t = (0); t < (q); t++) {
    int i, j;
    long long p;
    scanf("%d%d%lld", &i, &j, &p);
    M[p].push_back({i << 11 | j, t});
  }
  int S = max({n * 2, m * 2, 100});
  for (int p = (1); p < (S + 1); p++) {
    int s = p & 1;
    for (int i = (1); i < (n + 1); i++) {
      auto& bb = B[s ^ 1][i];
      sht[0] = bb << 1;
      sht[1] = bb >> 1;
      B[s][i] = ~((bb ^ sht[0]) & (bb ^ sht[1]) & (bb ^ B[s ^ 1][i + 1]) &
                  (bb ^ B[s ^ 1][i - 1]));
      B[s][i] ^= bb;
    }
    otocz(s, n, m);
    for (auto [j, t] : M[p]) {
      int i = j >> 11;
      j ^= i << 11;
      ans[t] = B[s][i][j];
    }
    M.erase(p);
  }
  S &= 1ll;
  long long alternate =
      (B[S][1][1] == B[S][1][2]) or (B[S][1][1] == B[S][2][1]);
  for (auto [p, V] : M)
    for (auto [j, t] : V) {
      int i = j >> 11;
      long long x = (S ^ p) & alternate;
      j ^= i << 11;
      ans[t] = B[S][i][j] ^ x;
    }
  for (int i = (0); i < (q); i++) printf("%d\n", ans[i]);
}
int main() {
  int t = 1;
  for (int tid = (1); tid < (t + 1); tid++) {
    solve();
  }
  return 0;
}
