#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a struct dijkstra{ const T T_INF=IN_INF!=-1?IN_INF:numeric_limits::max(); int n; vector>> g; vector dist; vector prev_idx; dijkstra(int n_):n(n_),g(n),dist(n,T_INF),prev_idx(n){} void add_edge(int u,int v,T cost,bool undirected=false){ assert(0<=u&&u s){ for(int i=0;i,vector>,greater>> pq; for(auto i:s){ dist[i]=0; pq.push({0,i}); } while(!pq.empty()){ auto [d,i]=pq.top(); pq.pop(); if(d!=dist[i]) continue; for(auto [ti,td]:g[i]){ if(dist[i]+td){s}); } bool path_exist(int i){ if(dist[i]==T_INF) return false; return true; } T get_dist(int i){ return dist[i]; } vector get_path(int i){ if(!path_exist(i)) return {}; vector ret={i}; while(dist[i]!=0){ i=prev_idx[i]; ret.push_back(i); } reverse(all(ret)); return ret; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; vector> h(n,vector(n)); rep(i,n){ rep(j,n){ cin >> h[i][j]; } } vector s(n); rep(i,n) cin >> s[i]; vector> a(n-1,vector(n)),b(n,vector(n-1)); rep(i,n-1){ rep(j,n){ cin >> a[i][j]; a[i][j]*=abs(h[i][j]+h[i+1][j]); } } rep(i,n){ rep(j,n-1){ cin >> b[i][j]; b[i][j]*=abs(h[i][j]+h[i][j+1]); } } dijkstra g(n*n+1); auto to=[&](ll i,ll j){ return i*n+j; }; rep(i,n-1){ rep(j,n){ ll p=h[i][j]+h[i+1][j]; ll l=-p-a[i][j]*abs(p),r=-p+a[i][j]*abs(p); if((i+j)%2==0){ g.add_edge(to(i,j),to(i+1,j),-l); g.add_edge(to(i+1,j),to(i,j),r); }else{ g.add_edge(to(i,j),to(i+1,j),r); g.add_edge(to(i+1,j),to(i,j),-l); } } } rep(i,n){ rep(j,n-1){ ll p=h[i][j]+h[i][j+1]; ll l=-p-b[i][j]*abs(p),r=-p+b[i][j]*abs(p); if((i+j)%2==0){ g.add_edge(to(i,j),to(i,j+1),-l); g.add_edge(to(i,j+1),to(i,j),r); }else{ g.add_edge(to(i,j),to(i,j+1),r); g.add_edge(to(i,j+1),to(i,j),-l); } } } rep(i,n){ rep(j,n){ if(s[i][j]=='=') g.add_edge(n*n,to(i,j),0); if(s[i][j]=='-'&&(i+j)%2==0) g.add_edge(n*n,to(i,j),0); if(s[i][j]=='+'&&(i+j)%2==1) g.add_edge(n*n,to(i,j),0); } } g.solve(n*n); ll q; cin >> q; while(q--){ ll r,c,e; cin >> r >> c >> e; r--; c--; ll d=g.get_dist(to(r,c)); bool ok=false; if((r+c)%2==0&&e<=h[r][c]-d) ok=true; if((r+c)%2==1&&e<=h[r][c]+d) ok=true; if(ok) cout << "Yes\n"; else cout << "No\n"; } }