#include <bits/stdc++.h>
long long p;
char s[1010][1010];
int t, n, x, y, m, d[1010][1010];
std::queue<std::pair<int, int>> q;
bool g(int i, int j, int c) {
  return i >= 0 && i < n && j >= 0 && j < m && s[i][j] == c;
}
bool f(int i, int j, int c) {
  if (i >= 0 && i < n && j >= 0 && j < m && !d[i][j])
    d[i][j] = c + 1, q.emplace(i, j);
  return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 0; i < n; i++) scanf("%s", s + i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (g(i + 1, j, s[i][j]) || g(i - 1, j, s[i][j]) ||
          g(i, j + 1, s[i][j]) || g(i, j - 1, s[i][j]))
        q.emplace(i, j), d[i][j] = 1;
  for (; q.size(); q.pop())
    int i = q.front().first, j = q.front().second,
        k = f(i + 1, j, d[i][j]) || f(i - 1, j, d[i][j]) ||
            f(i, j + 1, d[i][j]) || f(i, j - 1, d[i][j]);
  while (t--) {
    scanf("%d%d%lld", &x, &y, &p);
    x--, y--;
    printf("%c\n",
           s[x][y] ^ (p >= d[x][y] && d[x][y] && ((p - d[x][y]) & 1) == 0));
  }
}
