#include <bits/stdc++.h>
using namespace std;
string str[1005];
int tim[1005][1005];
int n, m, t;
int fx[] = {-1, +1, 0, 0};
int fy[] = {0, 0, -1, +1};
vector<pair<int, int> > cur;
bool okay(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
void dfs(int x, int y, int curr) {
  tim[x][y] = curr;
  cur.push_back(make_pair(x, y));
  for (int k = 0; k < 4; k++) {
    int tx = x + fx[k];
    int ty = y + fy[k];
    if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != str[x][y])
      continue;
    dfs(tx, ty, curr);
  }
}
char alt(char x) {
  if (x == '0')
    return '1';
  else
    return '0';
}
char query(int x, int y, long long curr) {
  if (tim[x][y] == -1) return str[x][y];
  long long diff = curr - 1LL * tim[x][y];
  if (diff % 2LL == 1LL)
    return alt(str[x][y]);
  else
    return str[x][y];
}
int main() {
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  memset(tim, -1, sizeof tim);
  vector<pair<int, int> > last;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) last.push_back(make_pair(i, j));
  }
  for (int curTim = 0; curTim <= n * m; curTim++) {
    for (int i = 0; i < last.size(); i++) {
      int x = last[i].first, y = last[i].second;
      char col = query(x, y, curTim);
      for (int k = 0; k < 4; k++) {
        int tx = x + fx[k];
        int ty = y + fy[k];
        if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != col)
          continue;
        dfs(tx, ty, curTim);
      }
    }
    last = cur;
    cur.clear();
    if (last.empty()) break;
  }
  while (t--) {
    int x, y;
    long long q;
    scanf("%d %d %lld", &x, &y, &q);
    x--, y--;
    char ans = query(x, y, q);
    cout << ans << endl;
  }
}
