#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b #define vl vector #define vii vector> #define vll vector> #define vvi vector> #define vvl vector> #define vvii vector>> #define vvll vector>> #define vst vector #define pii pair #define pll pair #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=200005,INF=15<<26; ll dis[2][MAX]; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); ll H,W,sh,sw;cin>>H>>W>>sh>>sw;sh--;sw--; vst S(H); for(int i=0;i>S[i]; } for(int q=0;q<2;q++){ for(int i=0;i Q; Q.push(mp(0,sh*W+sh)); dis[0][sh*W+sh]=0; while(!Q.empty()){ auto [t,po]=Q.front();Q.pop(); int h=po/W,w=po%W; for(int dh=-1;dh<=1;dh++){ for(int dw=-1;dw<=1;dw++){ if(dh==0&&dw==0) continue; int toh=h,tow=w; while(1){ toh+=dh; tow+=dw; if(toh<0||toh>=H||tow<0||tow>=W||S[toh][tow]=='#'||dis[t^1][toh*W+tow]>QQ; while(QQ--){ int h,w,t;cin>>h>>w>>t; h--;w--; if(dis[t&1][h*W+w]<=t) cout<<"Yes\n"; else cout<<"No\n"; } }