#include<cstdio>
#include<string>
#include<cmath>
int map[1010][1010];
bool f[1010][1010]={0};
int n,m;
int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int sx,sy,ex,ey;
bool isok;
int sta;
bool isval(int x,int y)
{
if(x<1||y<1||x>n||y>m)return false;
return true;
}
void dfs(int x,int y,int d,int change)
{
if(isok||change>2)return;
if(x==ex&&y==ey)
{
isok=true;
return;
}
else
{
int i;
if(!isok)
for(i=0;i<4;i++)
{
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(isval(tx,ty)&&(map[tx][ty]==0||(map[tx][ty]==sta&&tx==ex&&ty==ey))&&!f[tx][ty])
{
f[tx][ty]=1;
dfs(tx,ty,i,change+(d==i||d==4? 0:1));
f[tx][ty]=0;
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&m),n||m)
{
int i,j;
int cntZore=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
scanf("%d",&map[i][j]);
// int temp;
// scanf("%d",&temp);
// if(temp==0)cntZore++;
// map[i][j]=temp;
}
int k;
scanf("%d",&k);
for(i=0;i<k;i++)
{
// memset(f,0,sizeof(f));
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
// int num=labs(sx-ex)+labs(sy-ey);//num>cntZore&&
if(map[sx][sy]!=map[ex][ey]
||map[sx][sy]==0)
{
printf("NO\n");
}
else
{
f[sx][sy]=1;
sta=map[sx][sy];
isok=false;
dfs(sx,sy,4,0);
if(isok)printf("YES\n");
else printf("NO\n");
f[sx][sy]=0;
}
}
}
return 0;
}