#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 1005;
const int inf = 1<<30;
int n,m;
int x1,x2,y1,y2,flag;
int map[maxn][maxn];
int xs[] = {0,1,0,-1};
int ys[] = {1,0,-1,0};
void DFS( int x,int y,int d,int turn )
{
if( flag || turn > 2 ) return;
for ( int i = 0; i < 4; i ++ )
{
int xx = x + xs[i];
int yy = y + ys[i];
if( xx == x2 && yy == y2 )
{
if( (i != d && turn + 1 <= 2) || i == d )
{
flag = 1;
return;
}
}
if( xx >= 1 && xx <= n && yy >= 1 && yy <= m && !map[xx][yy] )
{
if( flag ) return;
map[xx][yy] = -1;
if( i != d )
DFS( xx,yy,i,turn+1 );
else
DFS( xx,yy,i,turn );
map[xx][yy] = 0;
}
}
}
int main()
{
//freopen("data.txt","r",stdin);
int q;
while( scanf("%d%d",&n,&m) == 2,(n||m) )
{
for( int i = 1; i <= n; i ++ )
{
for( int j = 1; j <= m; j ++ )
{
scanf("%d",&map[i][j]);
}
}
scanf("%d",&q);
for( int i = 1; i <= q; i ++ )
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
flag = 0;
if( map[x1][y1] == map[x2][y2] && map[x1][y1] )
DFS( x1,y1,-1,-1 );
if( flag )
puts("YES");
else
puts("NO");
}
}
return 0;
}