#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T>
T GCD(T a, T b) {
  long long t;
  while (a) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
template <typename T>
string toString(T a) {
  return to_string(a);
}
template <typename T>
void toInt(string s, T& x) {
  stringstream str(s);
  str >> x;
}
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int mul(int x, int y) { return (x * 1ll * y) % mod; }
inline int powr(int a, long long b) {
  int x = 1 % mod;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
const int N = 1e3 + 5;
int arr[N][N], n, m, q, temp[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void stuff() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      temp[i][j] = inf;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bool ok = false;
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && y >= 0 && x < n && y < m && arr[x][y] == arr[i][j]) {
          ok = true;
          break;
        }
      }
      if (ok) {
        temp[i][j] = 0;
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k], y = j + dy[k];
          if (x >= 0 && y >= 0 && x < n && y < m) {
            temp[x][y] = min(temp[x][y], 1);
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && y >= 0 && x < n && y < m) {
          temp[i][j] = min(temp[i][j], temp[x][y] + 1);
        }
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && y >= 0 && x < n && y < m) {
          temp[i][j] = min(temp[i][j], temp[x][y] + 1);
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      arr[i][j] = (c == '1');
    }
  }
  stuff();
  int x, y;
  long long p;
  while (q--) {
    cin >> x >> y >> p;
    x--;
    y--;
    int v = temp[x][y];
    if (v == inf) {
      cout << arr[x][y] << '\n';
    } else if (p <= v) {
      cout << arr[x][y] << '\n';
    } else {
      p -= v;
      cout << (arr[x][y] ^ (p & 1)) << '\n';
    }
  }
  return 0;
}
