#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MAX_N=1000000+50;
const int INF=0x3f3f3f3f;
const double EPS = 1e-10;
ll mod = 1e9+7;
/*
用到了剪枝,很巧妙
*/
int maze[1010][1010];
bool vis[1010][1010];
int sx,sy,ex,ey;
bool flag;
int n,m,q;
int dicx[]={1,-1,0,0};
int dicy[]={0,0,1,-1};
void dfs(int x, int y, int dic, int turns){
if(turns > 2 || flag) return; //转弯次数不能超过2
if(turns == 2 && (x - ex) != 0 && (y - ey) != 0) return; //次数为2的情况下不在同一直线 排除
if(x == ex && y == ey && turns <= 2){
flag = 1;
return;
}
for(int i = 0; i < 4; i++){
int xx = x + dicx[i];
int yy = y + dicy[i];
if(xx < 1 || xx > n || yy < 1 || yy > m || vis[xx][yy]) continue; //边界情况
if(maze[xx][yy] == 0 || (xx == ex && yy == ey)){
vis[xx][yy] = 1;
if(dic == -1 || dic == i) //如果在起点或者同向的情况turns不变及不转向 (同向为dir值)
dfs(xx,yy,i,turns);
else
dfs(xx,yy,i,turns+1);//否则turns+1
vis[xx][yy] = 0;
}
}
return;
}
int main(){
while(~scanf("%d%d",&n,&m)){
if(n == 0 && m == 0) break;
memset(maze,0,sizeof(maze));
for(int i = 1; i <= n; i++){
for(int j = 1;j <= m; j++){
scanf("%d",&maze[i][j]);
}
}
scanf("%d",&q);
for(int i = 0; i < q; i++){
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
memset(vis,0,sizeof(vis));
flag = 0;
if(maze[sx][sy] == maze[ex][ey] && maze[sx][sy])
dfs(sx,sy,-1,0); //初始方向设为-1
if(flag) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
/*
********
************
####....#.
#..###.....##....
###.......###### ### ###
........... #...# #...#
##*####### #.#.# #.#.#
####*******###### #.#.# #.#.#
...#***.****.*###.... #...# #...#
....**********##..... ### ###
....**** *****....
#### ####
###### ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
########################################## #----------#
#.....#......##.....#......##.....#......# #----------#
########################################## #----------#
#.#..#....#..##.#..#....#..##.#..#....#..# #----------#
########################################## ############
*/