#include <bits/stdc++.h>

using namespace std;

bool dfs(int xs,int ys,int xg,int yg,vector<vector<bool> >& canGo){
canGo[xs][ys]=false;
if(xs==xg&&ys==yg)return true;
if(canGo[xs+1][ys]){if(dfs(xs+1,ys,xg,yg,canGo))return true;}
if(canGo[xs-1][ys]){if(dfs(xs-1,ys,xg,yg,canGo))return true;}
if(canGo[xs][ys+1]){if(dfs(xs,ys+1,xg,yg,canGo))return true;}
if(canGo[xs][ys-1]){if(dfs(xs,ys-1,xg,yg,canGo))return true;}
return false;
}
int main(void){
int w,h,xs,ys,xg,yg,n;
bool ans,endflag;
vector<vector<bool> > blockmap;
while(true){
cin>>w>>h;
if(w==0&&h==0)break;
cin>>xs>>ys>>xg>>yg>>n;
blockmap=vector<vector<bool> >(w+2,vector<bool>(h+2,false));
for(int i=0;i<n;i++){
    int c,d,x,y;
    cin>>c>>d>>x>>y;
    if(c==2){
        blockmap[x+1][y+1]=true;
        blockmap[x+2][y+1]=true;
        blockmap[x+1][y+2]=true;
        blockmap[x+2][y+2]=true;
        if(d==0){
            blockmap[x+3][y+1]=true;
            blockmap[x+3][y+2]=true;
            blockmap[x+4][y+1]=true;
            blockmap[x+4][y+2]=true;
        }
        else {
            blockmap[x+1][y+2]=true;
            blockmap[x+2][y+3]=true;
            blockmap[x+1][y+4]=true;
            blockmap[x+2][y+4]=true;
        }
    }
}
ans=dfs(xs+1,ys+1,xg+1,yg+1,blockmap);
if(ans)cout<<"OK"<<endl;
else cout<<"NG"<<endl;
}
return 0;
}

