#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
bool a[1001][1001];
long long pasi[1001][1001];
char s[1001];
bool viz[1003][1003];
void bordare(int n, int m) {
  for (int i = 0; i <= n; i++) viz[i][0] = viz[i][m + 1] = 1;
  for (int j = 0; j <= m; j++) viz[0][j] = viz[n + 1][j] = 1;
}
struct punct {
  int x, y;
};
int d[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
queue<punct> Q;
void Lee() {
  punct vec;
  while (!Q.empty()) {
    punct crt = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      vec.x = crt.x + d[i][0];
      vec.y = crt.y + d[i][1];
      if (!viz[vec.x][vec.y]) {
        Q.push(vec);
        viz[vec.x][vec.y] = 1;
        pasi[vec.x][vec.y] = pasi[crt.x][crt.y] + 1;
      }
    }
  }
}
int main() {
  int n, m, t;
  cin >> n >> m >> t;
  bordare(n, m);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= m; j++) {
      a[i][j] = s[j - 1] - '0';
      pasi[i][j] = INF;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i > 1)
        if (a[i][j] == a[i - 1][j]) {
          pasi[i][j] = 0;
          viz[i][j] = 1;
          Q.push({i, j});
          continue;
        }
      if (j > 1)
        if (a[i][j] == a[i][j - 1]) {
          pasi[i][j] = 0;
          viz[i][j] = 1;
          Q.push({i, j});
          continue;
        }
      if (i < n)
        if (a[i][j] == a[i + 1][j]) {
          pasi[i][j] = 0;
          viz[i][j] = 1;
          Q.push({i, j});
          continue;
        }
      if (j < m)
        if (a[i][j] == a[i][j + 1]) {
          pasi[i][j] = 0;
          viz[i][j] = 1;
          Q.push({i, j});
          continue;
        }
    }
  Lee();
  while (t--) {
    int l, c;
    long long p;
    cin >> l >> c >> p;
    p -= pasi[l][c];
    if (p <= 0)
      cout << a[l][c] << '\n';
    else if (p % 2 == 0)
      cout << a[l][c] << '\n';
    else
      cout << 1 - a[l][c] << '\n';
  }
  return 0;
}
