#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, inf)); dist[sx][sy] = 0; deque> q; q.push_back({sx, sy}); while (!q.empty()) { auto [x, y] = q.front(); q.pop_front(); 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 (dist[nx][ny] <= dist[x][y]) break; dist[nx][ny] = dist[x][y] + 1; q.push_back({nx, ny}); } } } } int d1_cnt = 0, d2_cnt = 0; vector> d1s; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (dist[i][j] == 1) { d1_cnt++; d1s.push_back({i, j}); } if (dist[i][j] == 2) d2_cnt++; } } bool ne_ok = false; if (d2_cnt == 0) { for (int i = 0; i < d1s.size(); i++) { for (int j = i + 1; j < d1s.size(); j++) { if (max(abs(d1s[i].first - d1s[j].first), abs(d1s[i].second - d1s[j].second)) == 1) { ne_ok = true; } } } } else ne_ok = true; cin >> Q; while (Q--) { cin >> gx >> gy >> T; gx--; gy--; if (T == 1 && gx == sx && gy == sy) { cout << "No\n"; } else if (T % 2 == 1 && !ne_ok) { cout << "No\n"; } else if (dist[gx][gy] < inf && dist[gx][gy] <= T) { cout << "Yes\n"; } else { cout << "No\n"; } } }