#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> vis;
void dfs(int i, int j, int n, int m, string str[]) {
  int x[4] = {0, 0, -1, 1};
  int y[4] = {-1, 1, 0, 0};
  if (vis[i][j] != -1) return;
  vis[i][j] = 0;
  for (int k = 0; k < 4; k++) {
    if (i + x[k] >= 0 && i + x[k] < n && j + y[k] >= 0 && j + y[k] < m) {
      if (str[i][j] == str[i + x[k]][j + y[k]]) {
        dfs(i + x[k], j + y[k], n, m, str);
      }
    }
  }
}
void func() {
  int i, j;
  int n, m, qq, k;
  cin >> n >> m >> qq;
  string str[n];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  vis = vector<vector<int>>(n + 1, vector<int>(m + 1, -1));
  queue<pair<int, int>> q;
  int x[4] = {0, 0, -1, 1};
  int y[4] = {-1, 1, 0, 0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int flag = 0;
      for (int k = 0; k < 4; k++) {
        if (i + x[k] >= 0 && i + x[k] < n && j + y[k] >= 0 && j + y[k] < m) {
          if (str[i][j] == str[i + x[k]][j + y[k]]) {
            flag = 1;
          }
        }
      }
      if (flag == 1) {
        dfs(i, j, n, m, str);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vis[i][j] == 0) {
        q.push(make_pair(i, j));
      }
    }
  }
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int i = p.first;
    int j = p.second;
    for (int k = 0; k < 4; k++) {
      if (i + x[k] >= 0 && i + x[k] < n && j + y[k] >= 0 && j + y[k] < m) {
        if (vis[i + x[k]][j + y[k]] == -1) {
          vis[i + x[k]][j + y[k]] = vis[i][j] + 1;
          q.push(make_pair(i + x[k], j + y[k]));
        }
      }
    }
  }
  while (qq--) {
    long long int row, col, p;
    cin >> row >> col >> p;
    row--;
    col--;
    int val = vis[row][col];
    if (val == -1) {
      cout << str[row][col] << endl;
      continue;
    }
    if (p > val) {
      val = p - val;
      if (val % 2 == 0) {
        cout << str[row][col];
      } else {
        cout << '1' - str[row][col];
      }
    } else {
      cout << str[row][col];
    }
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j;
  int t, q;
  { func(); }
  return 0;
}
