#include <bits/stdc++.h>
using namespace std;
int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, +1, -1};
int n, m, t;
int ara[1005][1005];
string str[1005];
bool vis[1005][1005];
int ans[1005][1005];
queue<pair<int, int>> qu;
void process() {
  while (!qu.empty()) {
    pair<int, int> now;
    now.first = qu.front().first;
    now.second = qu.front().second;
    qu.pop();
    for (int k = 0; k < 4; k++) {
      int nx = now.first + dx[k];
      int ny = now.second + dy[k];
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny]) {
        vis[nx][ny] = true;
        ans[nx][ny] = ans[now.first][now.second] + 1;
        qu.push(make_pair(nx, ny));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> t;
  for (int i = 0; i < n; i++) cin >> str[i];
  bool same = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m &&
            str[nx][ny] == str[i][j]) {
          vis[i][j] = true;
          qu.push(make_pair(i, j));
          ans[i][j] = 1;
          same = false;
          break;
        }
      }
    }
  }
  process();
  int i, j;
  long long p;
  while (t--) {
    cin >> i >> j >> p;
    long long res = str[i - 1][j - 1] - '0';
    if (!same && ans[i - 1][j - 1] <= p)
      res ^= (max(p - ans[i - 1][j - 1] + 1LL, 0LL) % 2LL);
    cout << res << "\n";
  }
  return 0;
}
