#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T> read_n(int n) {
  vector<T> ret(n);
  for (int i = 0; i < n; i++) cin >> ret[i];
  return ret;
}
template <typename iter>
void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin) cout << " ";
    cout << *it;
  }
  cout << endl;
}
struct triple {
  int i, j, c;
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int q;
  cin >> q;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  auto idx = [&](int i, int j, int c) { return (i * m + j) * 2 + c; };
  vector<int> dist(n * m * 2, -1);
  queue<triple> u;
  auto push = [&](int i, int j, int c, int d) {
    int k = idx(i, j, c);
    if (dist[k] >= 0) return;
    dist[k] = d;
    u.push({i, j, c});
  };
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i + 1 < n && g[i + 1][j] == g[i][j]) {
        push(i, j, g[i][j] - '0', 0);
        push(i + 1, j, g[i + 1][j] - '0', 0);
      }
      if (j + 1 < m && g[i][j + 1] == g[i][j]) {
        push(i, j, g[i][j] - '0', 0);
        push(i, j + 1, g[i][j + 1] - '0', 0);
      }
    }
  }
  while (u.size()) {
    auto node = u.front();
    u.pop();
    int my_dist = dist[idx(node.i, node.j, node.c)];
    const int dr[] = {1, -1, 0, 0};
    const int dc[] = {0, 0, 1, -1};
    for (int k = 0; k < 4; k++) {
      int ii = node.i + dr[k];
      int jj = node.j + dc[k];
      if (ii < 0 || jj < 0 || ii >= n || jj >= m) continue;
      push(ii, jj, !node.c, my_dist + 1);
    }
  }
  while (q--) {
    int i, j;
    cin >> i >> j;
    i--;
    j--;
    long long p;
    cin >> p;
    int k = idx(i, j, g[i][j] - '0');
    if (0) cout << dist[k] << "\n";
    if (dist[k] < 0 || p <= dist[k]) {
      cout << g[i][j] << "\n";
    } else {
      int diff = (p + dist[k]) % 2;
      if (diff) {
        cout << (g[i][j] == '0' ? '1' : '0') << "\n";
      } else {
        cout << g[i][j] << "\n";
      }
    }
  }
  return 0;
}
