#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLI = pair<long long, int>;
using PLL = pair<long long, long long>;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
T gcd(T a, T b) {
  while (b) {
    T tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
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...);
}
long long qpow(long long a, long long b, int MOD) {
  if (b == 0) return 1;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
const int MOD = 1e9 + 7;
const int maxn = 2e6;
int fac[maxn + 5];
int invfac[maxn + 5];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= maxn; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
  invfac[maxn] = (int)(qpow(fac[maxn], MOD - 2, MOD));
  for (int i = maxn - 1; i >= 0; i--)
    invfac[i] = 1LL * invfac[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
  assert(0 <= k && n >= k);
  int tmp = (int)(1LL * invfac[k] * invfac[n - k] % MOD);
  return (int)(1LL * fac[n] * tmp % MOD);
}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, t;
  cin >> n >> m >> t;
  vector<vector<int>> mat(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '1') mat[i][j] = 1;
    }
  }
  vector<vector<int>> inimat(mat.begin(), mat.end());
  vector<int> res(t, 0);
  vector<vector<LL>> queries;
  vector<vector<vector<int>>> xy2tt(n, vector<vector<int>>(m));
  for (int tt = 0; tt < t; tt++) {
    int i, j;
    LL p;
    cin >> i >> j >> p;
    i--;
    j--;
    vector<LL> cur = {i, j, p};
    queries.push_back(cur);
    xy2tt[i][j].push_back(tt);
  }
  auto isgood = [&](const int i, const int j) {
    for (int di = 0; di < 4; di++) {
      int ni = i + dx[di], nj = j + dy[di];
      if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
      if (mat[i][j] == mat[ni][nj]) return true;
    }
    return false;
  };
  deque<PII> q;
  const int INF = (int)1e9 + 7;
  vector<vector<int>> f(n, vector<int>(m, INF));
  auto getAns = [&](const int i, const int j) {
    int fp = f[i][j];
    for (auto& tt : xy2tt[i][j]) {
      LL qp = queries[tt][2];
      if (fp == INF || fp > qp)
        res[tt] = inimat[i][j];
      else {
        if ((qp - fp) & 1) {
          res[tt] = mat[i][j];
        } else {
          res[tt] = 1 - mat[i][j];
        }
      }
    }
  };
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (isgood(i, j)) {
        q.emplace_back(i, j);
        f[i][j] = 1;
        getAns(i, j);
      }
    }
  }
  for (auto& p : q) mat[p.first][p.second] ^= 1;
  int time = 1;
  while (!q.empty()) {
    int sz = q.size();
    time++;
    for (int ssz = 0; ssz < sz; ssz++) {
      PII ij = q.front();
      q.pop_front();
      int i = ij.first, j = ij.second;
      for (int di = 0; di < 4; di++) {
        int ni = i + dx[di], nj = j + dy[di];
        if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
        if (f[ni][nj] < INF) continue;
        if (isgood(ni, nj)) {
          f[ni][nj] = time;
          getAns(ni, nj);
          q.emplace_back(ni, nj);
        }
      }
    }
    for (auto& p : q) mat[p.first][p.second] ^= 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (f[i][j] == INF) getAns(i, j);
    }
  }
  for (int tt = 0; tt < t; tt++) cout << res[tt] << '\n';
  return 0;
}
