#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1005;
const int oo = 1e9;
int n, m, t;
char mat[N][N];
short dist[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void bfs() {
  memset(dist, -1, sizeof dist);
  queue<int> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bool good = false;
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x < 0 or x >= n) continue;
        if (y < 0 or y >= m) continue;
        if (mat[i][j] != mat[x][y]) continue;
        good = true;
      }
      if (good) {
        dist[i][j] = 0;
        q.emplace((i << 16) | j);
      }
    }
  }
  while (!q.empty()) {
    int i = q.front() >> 16, j = q.front() & ((1 << 16) - 1);
    q.pop();
    for (int k = 0; k < 4; k++) {
      int x = i + dx[k], y = j + dy[k];
      if (x < 0 or x >= n) continue;
      if (y < 0 or y >= m) continue;
      if (dist[x][y] == -1) {
        dist[x][y] = dist[i][j] + 1;
        q.emplace((x << 16) | y);
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) scanf(" %s", mat[i]);
  bfs();
  while (t--) {
    int i, j;
    ll p;
    scanf("%d %d %lld", &i, &j, &p);
    i--, j--;
    if (dist[i][j] == -1 or p <= dist[i][j]) {
      printf("%c\n", mat[i][j]);
    } else {
      p -= dist[i][j];
      printf("%c\n", mat[i][j] ^ int(p % 2));
    }
  }
}
