#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> 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]); } } auto f=[&](ll r,ll c,ll x){ if(h[r][c]==x) return true; if(h[r][c]> q; while(q--){ ll r,c,e; cin >> r >> c >> e; r--; c--; bool ng=false; ng|=!f(r,c,e); ng|=(0<=r-1&&!(abs(h[r-1][c]+e)<=a[r-1][c]||(f(r-1,c,-a[r-1][c]-e)||f(r-1,c,a[r-1][c]-e)))); ng|=(0<=c-1&&!(abs(h[r][c-1]+e)<=a[r][c-1]||(f(r,c-1,-b[r][c-1]-e)||f(r,c-1,b[r][c-1]-e)))); ng|=(r+1