#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> dist0(H, vector(W, inf)); vector> dist1(H, vector(W, inf)); dist0[sx][sy] = 0; deque> q; q.push_back({0, sx * W + sy}); while (!q.empty()) { assert(q.size() <= 2 * H * W); 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 (dist1[nx][ny] <= dist0[x][y]) break; dist1[nx][ny] = dist0[x][y] + 1; q.push_back({1, nx * W + ny}); } else { if (dist0[nx][ny] <= dist1[x][y]) break; dist0[nx][ny] = dist1[x][y] + 1; q.push_back({0, nx * W + ny}); } } } } } cin >> Q; while (Q--) { cin >> gx >> gy >> T; gx--; gy--; int di = (T % 2 == 0 ? dist0[gx][gy] : dist1[gx][gy]); if (di < inf && di <= T) { cout << "Yes\n"; } else { cout << "No\n"; } } }