#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> a;
vector<vector<int>> moves;
vector<vector<int>> visited;
int n, m, t;
void bfs() {
  queue<pair<int, int>> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (moves[i][j] == 0) {
        q.push(make_pair(i, j));
        visited[i][j] = 1;
      }
    }
  }
  while (!q.empty()) {
    pair<int, int> temp = q.front();
    int x = temp.first, y = temp.second;
    q.pop();
    if (x != 0 && visited[x - 1][y] == 0) {
      moves[x - 1][y] = 1 + moves[x][y];
      q.push(make_pair(x - 1, y));
      visited[x - 1][y] = 1;
    }
    if (x != n - 1 && visited[x + 1][y] == 0) {
      moves[x + 1][y] = 1 + moves[x][y];
      q.push(make_pair(x + 1, y));
      visited[x + 1][y] = 1;
    }
    if (y != 0 && visited[x][y - 1] == 0) {
      moves[x][y - 1] = 1 + moves[x][y];
      q.push(make_pair(x, y - 1));
      visited[x][y - 1] = 1;
    }
    if (y != m - 1 && visited[x][y + 1] == 0) {
      moves[x][y + 1] = 1 + moves[x][y];
      q.push(make_pair(x, y + 1));
      visited[x][y + 1] = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> t;
  bool flag = false;
  moves.resize(n, vector<int>(m, -1));
  visited.resize(n, vector<int>(m, 0));
  a.resize(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      a[i][j] = s[j] - '0';
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j != 0 && a[i][j - 1] == a[i][j]) {
        moves[i][j] = 0;
        flag = true;
      }
      if (j != m - 1 && a[i][j + 1] == a[i][j]) {
        moves[i][j] = 0;
        flag = true;
      }
      if (i != 0 && a[i - 1][j] == a[i][j]) {
        moves[i][j] = 0;
        flag = true;
      }
      if (i != n - 1 && a[i + 1][j] == a[i][j]) {
        moves[i][j] = 0;
        flag = true;
      }
    }
  }
  bfs();
  while (t--) {
    int x, y;
    long long int p;
    cin >> x >> y >> p;
    x--, y--;
    if (flag == false) {
      cout << a[x][y] << '\n';
    } else {
      int temp = moves[x][y];
      if (p <= temp) {
        cout << a[x][y] << '\n';
      } else {
        p -= temp;
        if (p % 2 == 0) {
          cout << a[x][y] << '\n';
        } else {
          cout << (a[x][y] + 1) % 2 << '\n';
        }
      }
    }
  }
}
