#include using namespace std; const int inf = 1e9; int main() { int H, W, sx, sy, Q, gx, gy, T; cin >> H >> W >> sx >> sy; sx--; sy--; vector S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector>> dist(H, vector>(W, make_pair(inf, inf))); dist[sx][sy].first = 0; deque> q; q.push_back({0, sx * W + sy}); while (!q.empty()) { auto [b, xy] = q.front(); q.pop_front(); int x = xy / W, y = xy % W; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx == 0 && dy == 0) continue; int nx = x, ny = y; while (true) { nx += dx; ny += dy; if (!(0 <= nx && nx < H && 0 <= ny && ny < W)) break; if (S[nx][ny] == '#') break; if (b == 0) { if (dist[nx][ny].second <= dist[x][y].first) break; dist[nx][ny].second = dist[x][y].first + 1; q.push_back({1, nx * W + ny}); } else { if (dist[nx][ny].first <= dist[x][y].second) break; dist[nx][ny].first = dist[x][y].second + 1; q.push_back({0, nx * W + ny}); } } } } } cin >> Q; while (Q--) { cin >> gx >> gy >> T; gx--; gy--; int di = (T % 2 == 0 ? dist[gx][gy].first : dist[gx][gy].second); if (di < inf && di <= T) { cout << "Yes\n"; } else { cout << "No\n"; } } }