#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
const int MAXN = 1e3 + 10, MAXQ = 3e5 + 10, MAXL = 20, ALP = 26, MOD = 1e9 + 7,
          MAXK = 17, MAXA = 30, MAXB = 24, MAXBB = (1 << MAXB);
const string no = "NO\n", yes = "YES\n";
const int hA[4] = {1, 0, -1, 0}, kA[4] = {0, 1, 0, -1};
const long long INF = 1e18 + 10;
int n, m, nq;
long long d[MAXN][MAXN];
string g[MAXN];
void solve() {
  cin >> n >> m >> nq;
  for (int i = 0; i < n; i++) cin >> g[i];
  queue<pair<int, int>> q;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      d[i][j] = INF;
      bool bad = 1;
      for (int k = 0; k < 4; k++) {
        int ni = i + hA[k], nj = j + kA[k];
        if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
        if (g[ni][nj] == g[i][j]) bad = 0;
      }
      if (!bad) q.push({i, j}), d[i][j] = 0;
    }
  while ((int)q.size()) {
    auto c = q.front();
    q.pop();
    int i = c.first, j = c.second;
    for (int k = 0; k < 4; k++) {
      int ni = i + hA[k], nj = j + kA[k];
      if (ni < 0 || ni >= n || nj < 0 || nj >= m || d[ni][nj] < INF) continue;
      d[ni][nj] = d[i][j] + 1, q.push({ni, nj});
    }
  }
  while (nq--) {
    int i, j;
    long long p;
    cin >> i >> j >> p, --i, --j, --p;
    cerr << p - d[i][j] + 1 << "\n";
    if (d[i][j] > p)
      cout << g[i][j] << '\n';
    else if ((p - d[i][j] + 1) & 1)
      cout << char(g[i][j] ^ '0' ^ '1') << '\n';
    else
      cout << g[i][j] << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
}
