#include <cstdio>
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
#define d(x) cout<<(x)<<endl;
typedef long long ll;
const int N = 1e3 + 10;
const int base = 60;
int n, m, q, s1, s2, e1, e2;
int a[N][N]; //存迷宫
int vis[N][N]; //标记数组
int dir[][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
struct node{
int x, y, turn, di; // 表示 位置,转向次数,来时的方向
node(int x, int y, int turn, int di):x(x),y(y),turn(turn),di(di){}
};
int f(int x, int y){
if(x >= 1 && x <= n && y >= 1 && y <= m)
return 1;
return 0;
}
int bfs(){
if(!a[s1][s2] || !a[e1][e2] || a[s1][s2] != a[e1][e2])
return 0;
a[e1][e2] = 0; // 这里改变了值,bfs完了要改回去
queue<node> q;
q.push(node(s1, s2, -1, -1));
while(!q.empty()){
node cnt = q.front();
q.pop();
if(cnt.x == e1 && cnt.y == e2 && cnt.turn <= 2){
return 1;
}
if(cnt.turn == 3)
continue;
for(int i = 0; i < 4; i++){
int tx = cnt.x + dir[i][0];
int ty = cnt.y + dir[i][1];
if(!vis[tx][ty] && f(tx, ty) && a[tx][ty] == 0){
vis[tx][ty] = 1;
q.push(node(tx, ty, (i == cnt.di ? cnt.turn : cnt.turn + 1), i));
}
}
}
return 0;
}
int main() {
while(scanf("%d%d", &n, &m)){
if(n == 0 && m == 0)
break;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
scanf("%d", &a[i][j]);
}
}
scanf("%d", &q);
while(q--){
memset(vis, 0, sizeof(vis)); // 每次bfs之前要清空
scanf("%d%d%d%d", &s1, &s2, &e1, &e2);
int temp = a[e1][e2];
printf(bfs() ? "YES\n" : "NO\n");
a[e1][e2] = temp; // 改回去
}
}
return 0;
}