#include <iostream>
#include <vector>

using namespace std;

int needleX[4]={0,1,0,-1};
int needleY[4]={1,0,-1,0};

bool dfs(int x,int y,int xg,int yg,vector<vector<bool> > &map){
  if(x==xg && y==yg) return true;

  map[x][y]=false;

  for(int i=0;i<4;i++){
    int nextx=needleX[i]+x;
    int nexty=needleY[i]+y;

    if(map[nextx][nexty]){
      bool flag=dfs(nextx,nexty,xg,yg,map);
      if(flag) return true;
    }
  }
  return false;
    
}

int main(){
    while(true){
        int W,H;
        cin >> W >> H;
        if(W==0 && H==0)break;
        
        int xs,ys,xg,yg;
        cin >> xs >> ys;
        cin >> xg >> yg;
        int n;
        cin >> n;
        vector<vector<int> > cmap(W+2,vector<int>(H+2,0));
	vector<vector<bool> > map(W+2,vector<bool>(H+2,false));

	for(int i=0;i<n;i++){
	  int color,d,x,y;
	  cin >> color >> d >> x >> y;
	  for(int j=0;j<2;j++){
            for(int k=0;k<4;k++){
	      if(d==1)cmap[x+j][y+k]=color;
	      else cmap[x+k][y+j]=color;
	    }
	  }
	}
	/*
	for(int i=0;i<W+2;i++){
	  for(int j=0;j<H+2;j++){
	    cout << " " << cmap[i][j];
	  }
	  cout << endl;
	} 
	*/ 
        int c=cmap[xs][ys];
	for(int i=1;i<=W;i++){
	  for(int j=1;j<=H;j++){
	    if(cmap[i][j]==c)map[i][j]=true;
	  }
	}
	if(!(map[xs][ys] && map[xg][yg])){
	  cout << "NG" << endl;
	  return 0;
	}
	/*
	for(int i=0;i<W+2;i++){
	  for(int j=0;j<H+2;j++){
	    if(map[i][j])cout << ".";
	    else cout << "#";
	  }
	  cout << endl;
	}
	cout << endl;
	*/
        bool flag=dfs(xs,ys,xg,yg,map);
        if(flag) cout << "OK" << endl;
        else cout << "NG" << endl;
	
    }
  return 0;
}