#include <iostream>
#define MAXN 1001
#include <queue>
using namespace std;
int mat[MAXN][MAXN];
int mark[MAXN][MAXN];
int n, m, sx, sy, ex, ey, q;
//int mov[ 4 ][ 2 ] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
//搜索的顺序影响结果
int mov[ 4 ][ 2 ] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Node {
int x;
int y;
int turn;
int dir;
};
void BFS() {
queue<Node> Q;
Node p, q;
p.x = sx; p.y = sy;
mark[ sx ][ sy ] = 0;
p.dir = -1; p.turn = 0;
Q.push(p);
while(!Q.empty()) {
q = Q.front();
Q.pop();
if(q.x == ex && q.y == ey) {
puts("YES");
return ;
}
//0下, 1上, 2左, 3右
for(int i = 0; i < 4; ++ i) {
p.x = q.x + mov[ i ][ 0 ];
p.y = q.y + mov[ i ][ 1 ];
p.turn = q.turn;
p.dir = q.dir;
if(q.dir == -1) {
p.dir = i;
p.turn = 0;
}
else if(q.dir != i) {
p.turn ++;
p.dir = i;
}
if(p.x < 1 || p.x > n || p.y < 1 || p.y > m) continue;
if(mat[ p.x ][ p.y ] && !(p.x == ex && p.y == ey) || p.turn > 2) continue;
if(mark[ p.x ][ p.y ] > p.turn) {
mark[ p.x ][ p.y ] = p.turn;
Q.push(p);
}
}
}
puts("NO");
}
void res() {
scanf("%d", &q);
while(q --) {
scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
if(sx == ex && sy == ey) {
puts("NO");
continue;
}
if(mat[ sx ][ sy ] != mat[ ex ][ ey ] || mat[ sx ][ sy ] == 0 || mat[ ex ][ ey ] == 0) {
puts("NO");
continue;
}
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= m; ++ j) {
mark[ i ][ j ] = 10000000;
}
}
BFS();
}
}
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", &mat[ i ][ j ]);
}
}
res();
}
return 0;
}