func_code_string: #include <bits/stdc++.h>   using namespace std;   inline bool valid(int64_t x, int64_t y, int64_t n, int64_t m) {     return (x >= 0 && x < n && y >= 0 && y < m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int64_t n, m, q;     cin >> n >> m >> q;     vector<string> v(n);     for (int64_t i = 0; i < n; ++i) {       cin >> v[i];     }     int64_t dx[4] = {-1, 1, 0, 0};     int64_t dy[4] = {0, 0, -1, 1};     queue<pair<int64_t, int64_t> > qu;     vector<vector<int64_t> > dis(n, vector<int64_t>(m, -1));     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         int64_t k = 0;         for (; k < 4; ++k) {           int64_t x = i + dx[k], y = j + dy[k];           if (valid(x, y, n, m)) {             if (v[i][j] == v[x][y]) {               break;             }           }         }         if (k < 4) {           qu.push({i, j});           dis[i][j] = 0;         }       }     }     while (!qu.empty()) {       pair<int64_t, int64_t> p = qu.front();       qu.pop();       for (int64_t k = 0; k < 4; ++k) {         int64_t x = p.first + dx[k], y = p.second + dy[k];         if (valid(x, y, n, m) && dis[x][y] == -1) {           dis[x][y] = 1 + dis[p.first][p.second];           qu.push({x, y});         }       }     }     while (q--) {       int64_t i, j, p;       cin >> i >> j >> p;       --i;       --j;       char ans = v[i][j];       if (dis[i][j] > -1 && p - dis[i][j] > 0 && (p - dis[i][j]) % 2 != 0) {         if (ans ==  1 )           ans =  0 ;         else           ans =  1 ;       }       cout << ans << endl;     }     return 0;   }   