#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
long long gi() {
  long long x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m, q, a[N][N], dis01[N][N], dis10[N][N], dx[4] = {1, 0, 0, -1},
                                                dy[4] = {0, 1, -1, 0};
char s[N];
void bfs(int dis[N][N], int s) {
  static bool vis[N][N];
  memset(vis, 0, sizeof(vis));
  queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == s) q.push(make_pair(i, j)), vis[i][j] = 1;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int d = 0; d < 4; d++) {
      int xx = x + dx[d], yy = y + dy[d];
      if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
      if (!vis[xx][yy]) {
        vis[xx][yy] = 1;
        dis[xx][yy] = dis[x][y] + 1;
        q.push(make_pair(xx, yy));
      }
    }
  }
}
int main() {
  cin >> n >> m >> q;
  bool same = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      a[i][j] = s[j] - '0';
      if ((i + j) & 1) a[i][j] ^= 1;
      same &= (a[i][j] == a[1][1]);
    }
  }
  if (!same) {
    bfs(dis01, 0);
    bfs(dis10, 1);
  }
  while (q--) {
    int x = gi(), y = gi(), ans;
    long long t = gi();
    if (same) {
      ans = a[x][y];
    } else {
      int dis;
      if (a[x][y] == 0)
        dis = dis10[x][y];
      else
        dis = dis01[x][y];
      if (t < dis)
        ans = a[x][y];
      else
        ans = a[x][y] ^ ((t - dis) & 1) ^ 1;
    }
    if ((x + y) & 1) ans ^= 1;
    cout << ans << '\n';
  }
  return 0;
}
