#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " || ";
  __f(comma + 1, args...);
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                  Container const& x) {
  os << "{ ";
  for (auto& y : x) os << y << " ; ";
  return os << "}";
}
template <class X, class Y>
ostream& operator<<(ostream& os, pair<X, Y> const& p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long L = 1e3 + 5;
long long arr[L][L];
long long vis[L][L];
long long dist[L][L];
long long n, m, t;
bool check(long long x, long long y) {
  if (x < 1 || x > n) return false;
  if (y < 1 || y > m) return false;
  if (vis[x][y] == 1) return false;
  vis[x][y] = 1;
  return true;
}
bool check2(long long x, long long y) {
  if (x > 1 && arr[x - 1][y] == arr[x][y]) return true;
  if (x < n && arr[x + 1][y] == arr[x][y]) return true;
  if (y > 1 && arr[x][y - 1] == arr[x][y]) return true;
  if (y < m && arr[x][y + 1] == arr[x][y]) return true;
  return false;
}
long long F;
void bfs() {
  deque<pair<long long, long long> > q;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      vis[i][j] = 0;
      if (check2(i, j)) {
        q.push_back({i, j});
        vis[i][j] = 1;
        dist[i][j] = 0;
      }
    }
  }
  if ((long long)(q.size()) == 0) {
    F = 1;
  }
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop_front();
    if (check(p.first - 1, p.second)) {
      q.push_back({p.first - 1, p.second});
      dist[p.first - 1][p.second] = dist[p.first][p.second] + 1;
    }
    if (check(p.first + 1, p.second)) {
      q.push_back({p.first + 1, p.second});
      dist[p.first + 1][p.second] = dist[p.first][p.second] + 1;
    }
    if (check(p.first, p.second + 1)) {
      q.push_back({p.first, p.second + 1});
      dist[p.first][p.second + 1] = dist[p.first][p.second] + 1;
    }
    if (check(p.first, p.second - 1)) {
      q.push_back({p.first, p.second - 1});
      dist[p.first][p.second - 1] = dist[p.first][p.second] + 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> t;
  for (long long i = 1; i <= n; i++) {
    string temp;
    cin >> temp;
    for (long long j = 1; j <= m; j++) {
      arr[i][j] = temp[j - 1] - '0';
    }
  }
  bfs();
  while (t--) {
    long long i, j, p;
    cin >> i >> j >> p;
    if (F == 1) {
      cout << arr[i][j] << '\n';
      continue;
    }
    long long d = dist[i][j];
    long long req = p - d;
    if (req < 0) {
      cout << arr[i][j] << '\n';
    } else if (req % 2 == 0) {
      cout << arr[i][j] << '\n';
    } else {
      cout << 1 - arr[i][j] << '\n';
    }
  }
  return 0;
}
