#include <bits/stdc++.h>
using namespace std;
long long p;
char c[1010];
string s[1010];
queue<pair<int, int>> q;
int t, n, x, y, m, d[1010][1010];
void f(int i, int j, int c) {
  if (!d[i][j]) d[i][j] = c + 1, q.emplace(i, j);
}
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 0; i <= m + 1; i++) c[i] = '.';
  s[0] = s[n + 1] = string(c);
  for (int i = 1; i <= n; i++) scanf("%s", c + 1), s[i] = string(c);
  for (int i = 1; i <= n; i++) d[i][0] = d[i][m + 1] = 1;
  for (int j = 1; j <= m; j++) d[0][j] = d[n + 1][j] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      bool flag = false;
      if (s[i][j] == s[i - 1][j])
        flag = true;
      else if (s[i][j] == s[i + 1][j])
        flag = true;
      else if (s[i][j] == s[i][j - 1])
        flag = true;
      else if (s[i][j] == s[i][j + 1])
        flag = true;
      if (flag) q.emplace(i, j), d[i][j] = 1;
    }
  while (q.size()) {
    int i = q.front().first, j = q.front().second;
    f(i + 1, j, d[i][j]);
    f(i - 1, j, d[i][j]);
    f(i, j + 1, d[i][j]);
    f(i, j - 1, d[i][j]);
    q.pop();
  }
  while (t--) {
    scanf("%d%d%lld", &x, &y, &p);
    if (p < d[x][y] || d[x][y] == 0)
      printf("%c", s[x][y]);
    else if ((p - d[x][y]) & 1)
      printf("%c", s[x][y]);
    else
      printf("%d", 1 - (s[x][y] - '0'));
    puts("");
  }
}
