#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;
using ll = long long;
int main() {
  int N, M, t;
  cin >> N >> M >> t;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  vector<int> iq(t), jq(t);
  vector<ll> p(t);
  for (int i = 0; i < t; i++) {
    cin >> iq.at(i) >> jq.at(i) >> p.at(i);
    iq.at(i)--;
    jq.at(i)--;
  }
  vector<vector<int>> dist(N, vector<int>(M, 1000000));
  queue<pp> q;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      bool flag = false;
      for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ni < 0 || nj < 0 || ni >= N || nj >= M) {
          continue;
        }
        if (S.at(i).at(j) == S.at(ni).at(nj)) {
          flag = true;
        }
      }
      if (flag) {
        dist.at(i).at(j) = 0;
        q.push(make_pair(i, j));
      }
    }
  }
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int ni = i + dx[k];
      int nj = j + dy[k];
      if (ni < 0 || nj < 0 || ni >= N || nj >= M) {
        continue;
      }
      if (dist.at(ni).at(nj) == 1000000) {
        dist.at(ni).at(nj) = dist.at(i).at(j) + 1;
        q.push(make_pair(ni, nj));
      }
    }
  }
  for (int k = 0; k < t; k++) {
    int i = iq.at(k);
    int j = jq.at(k);
    if (dist.at(i).at(j) == 1000000) {
      cout << S.at(i).at(j) << endl;
    } else if (p.at(k) < dist.at(i).at(j)) {
      cout << S.at(i).at(j) << endl;
    } else {
      ll x = (ll)S.at(i).at(j) + (ll)p.at(k) - (ll)dist.at(i).at(j);
      x %= 2;
      cout << x << endl;
    }
  }
}
