#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; struct SSSP { private: struct Edge { int to; ll cost; }; int n; vector> adj; vector d; vector prev_node; static constexpr ll INF = 1LL << 62; public: explicit SSSP(int n) : n(n), adj(n) {} void add_edge(int from, int to, ll cost = 1) { adj[from].push_back({to, cost}); } void reset() { d.assign(n, INF); prev_node.assign(n, -1); } // BFS void bfs(int s) { reset(); queue q; d[s] = 0; q.push(s); while (!q.empty()) { int v = q.front(); q.pop(); for (auto &e : adj[v]) { if (d[e.to] != INF) continue; d[e.to] = d[v] + 1; prev_node[e.to] = v; q.push(e.to); } } } // 01BFS void zero_one_bfs(int s) { reset(); deque q; d[s] = 0; q.push_back(s); while (!q.empty()) { int v = q.front(); q.pop_front(); for (auto &e : adj[v]) { ll nd = d[v] + e.cost; if (nd >= d[e.to]) continue; d[e.to] = nd; prev_node[e.to] = v; if (e.cost == 0) q.push_front(e.to); else q.push_back(e.to); } } } // dijkstra void dijkstra(int s) { reset(); using P = pair; priority_queue, greater

> pq; d[s] = 0; pq.push({0, s}); while (!pq.empty()) { auto [cost, v] = pq.top(); pq.pop(); if (cost > d[v]) continue; for (auto &e : adj[v]) { ll nd = d[v] + e.cost; if (nd >= d[e.to]) continue; d[e.to] = nd; prev_node[e.to] = v; pq.push({nd, e.to}); } } } // Bellman-Ford // 負閉路から到達できる頂点のdistは-INF // 戻り値: 負閉路が存在すれば true bool bellman_ford(int s) { reset(); d[s] = 0; vector> edges; for (int v = 0; v < n; v++) for (auto &e : adj[v]) edges.emplace_back(v, e.to, e.cost); for (int i = 0; i < n; i++) { bool updated = false; for (auto &[from, to, cost] : edges) { if (d[from] == INF) continue; if (d[from] + cost < d[to]) { d[to] = d[from] + cost; prev_node[to] = from; updated = true; if (i == n - 1) d[to] = -INF; } } if (!updated) break; } queue q; for (int v = 0; v < n; v++) if (d[v] == -INF) q.push(v); while (!q.empty()) { int v = q.front(); q.pop(); for (auto &e : adj[v]) { if (d[e.to] != -INF) { d[e.to] = -INF; q.push(e.to); } } } bool has_negative_cycle = false; for (int v = 0; v < n; v++) if (d[v] == -INF) { has_negative_cycle = true; break; } return has_negative_cycle; } ll dist(int v) const { if (d[v] == INF) return -1; if (d[v] == -INF) return -2; return d[v]; } vector path(int g) const { if (d[g] == INF || d[g] == -INF) return {}; vector res; for (int v = g; v != -1; v = prev_node[v]) res.push_back(v); reverse(res.begin(), res.end()); return res; } }; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int h, w; cin >> h >> w; int sx, sy; cin >> sx >> sy; sx--; sy--; auto f = [&](int x, int y) { if (x == 8 || y == 8) return false; int d = abs(x - y); if (d == 4 || d == 1 || d == 7) return false; if ((d == 2 || d == 6) && x % 2 == 0) return false; return true; }; auto tr = [&](int i, int j, int d, int x) { return 2 * (9 * (i * w + j) + d) + x; }; vector s(h); rep(i, h) { cin >> s[i]; } SSSP g(h * w * 18); rep(i, h) rep(j, w) { if (s[i][j] == '#') continue; rep(k, 8) { int nx = i + dx[k]; int ny = j + dy[k]; if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue; if (s[nx][ny] == '#') continue; rep(l, 9) { g.add_edge(tr(i, j, l, 0), tr(nx, ny, k, 0), (k == l ? 0 : 1)); if (f(l, k)) { g.add_edge(tr(i, j, l, 0), tr(nx, ny, k, 1), (k == l ? 0 : 1)); } g.add_edge(tr(i, j, l, 1), tr(nx, ny, k, 1), (k == l ? 0 : 1)); } } } g.zero_one_bfs(tr(sx, sy, 8, 0)); int q; cin >> q; while (q--) { int d0 = 1 << 30; int d1 = 1 << 30; int gx, gy, t; cin >> gx >> gy >> t; gx--; gy--; rep(i, 9) { if (g.dist(tr(gx, gy, i, 0)) != -1) d0 = min((ll)d0, g.dist(tr(gx, gy, i, 0))); if (g.dist(tr(gx, gy, i, 1)) != -1) d1 = min((ll)d1, g.dist(tr(gx, gy, i, 1))); } // cout << d1 << " " << d0 << endl; if (d1 <= t || (d0 <= t && d0 % 2 == t % 2)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }