#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
using namespace std;
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, t;
  cin >> n >> m >> t;
  vector<string> vs(n);
  for (int i = 0; i < n; i++) cin >> vs[i];
  {
    vector<string> tmp1(n, string(m, 'X')), tmp2(n, string(m, 'X'));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (i % 2 == 0) {
          if (j % 2 == 0)
            tmp1[i][j] = '0', tmp2[i][j] = '1';
          else
            tmp1[i][j] = '1', tmp2[i][j] = '0';
        } else {
          if (j % 2 == 1)
            tmp1[i][j] = '0', tmp2[i][j] = '1';
          else
            tmp1[i][j] = '1', tmp2[i][j] = '0';
        }
      }
    }
    if (vs == tmp1 or vs == tmp2) {
      while (t--) {
        long long i, j, p;
        cin >> i >> j >> p;
        i--;
        j--;
        cout << vs[i][j] << "\n";
      }
      return 0;
    }
  }
  vector<vector<int>> d(n, vector<int>(m, -1));
  queue<pair<int, int>> q;
  {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < 4; k++) {
          int nh = i + dh[k];
          int nw = j + dw[k];
          if (nh < 0 or nh >= n or nw < 0 or nw >= m) continue;
          if (vs[nh][nw] == vs[i][j]) {
            d[i][j] = 0, q.emplace(i, j);
            break;
          }
        }
      }
    }
  }
  while (!q.empty()) {
    int h, w;
    tie(h, w) = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nh = h + dh[i];
      int nw = w + dw[i];
      if (nh < 0 or nh >= n or nw < 0 or nw >= m) continue;
      if (d[nh][nw] != -1) continue;
      d[nh][nw] = d[h][w] + 1;
      q.emplace(nh, nw);
    }
  }
  while (t--) {
    long long i, j, p;
    cin >> i >> j >> p;
    i--;
    j--;
    if (p <= d[i][j]) {
      cout << vs[i][j] << "\n";
    } else {
      p -= d[i][j];
      int cur = vs[i][j] - '0';
      if (p % 2 == 1) {
        cout << (cur ^ 1) << "\n";
      } else {
        cout << cur << "\n";
      }
    }
  }
  return 0;
}
