#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
#define MAX 105
#define Nll -1
int w,h;
int xs,ys,xg,yg;
int blockNm;
int map[MAX][MAX];
typedef queue < pair<int,int> > Queue;
void setBlock(int color,int dir,int x,int y){
	int dx[]={2,0};
	int dy[]={0,2};
	int xb=x,yb=y;//x_base,y_base
	for(int i=0;i<2;i++,xb+=dx[dir],yb+=dy[dir]){
		map[yb][xb]
		        =map[yb][xb+1]
		        =map[yb+1][xb]
		        =map[yb+1][xb+1]=color;
	}
}
void init(){
	for(int i=0;i<MAX;i++)for(int j=0;j<MAX;j++)map[i][j]=-1;
}
void print(){
	for(int i=0;i<=h+1;i++){for(int j=0;j<=w+1;j++)printf("%2d",map[i][j]);cout<<endl;}
}
bool isGoal(int xs,int ys,int xg,int yg){
	int color=map[xs][ys];
	if(color==Nll)return false;
	int dx[]={ 0, 1, 0,-1};
	int dy[]={-1, 0, 1, 0};
	//cout<<"["<<w<<" "<<h<<"]"<<endl;
	Queue q;
	q.push(pair<int,int>(xs,ys));
	while(!q.empty()){
		pair<int,int> cur=q.front();q.pop();
	//	cout<<"cur("<<cur.first<<","<<cur.second<<")"<<endl;
		if(cur.first==xg&&cur.second==yg)return true;
		for(int i=0;i<4;i++){
//			cout<<"    next("<<cur.first+dx[i]<<","<<cur.second+dy[i]<<")"<<map[cur.first+dy[i]][cur.second+dx[i]]<<endl;
			if(cur.first+dx[i]<1||cur.first+dx[i]>w
					||cur.second+dy[i]<1||cur.second+dy[i]>h
					||map[cur.second+dy[i]][cur.first+dx[i]]!=color)continue;
			q.push(pair<int,int>(cur.first+dx[i],cur.second+dy[i]));
			map[cur.second+dy[i]][cur.first+dx[i]]=99;
		}
	}
	return false;
}
int main(){
	while(cin>>w>>h&&(w||h)){
		init();
		cin>>xs>>ys>>xg>>yg>>blockNm;
		for(int i=0;i<blockNm;i++){
			int color,dir,x,y;
			cin>>color>>dir>>x>>y;
			setBlock(color,dir,x,y);
		}
		//print();
		string ans=isGoal(xs,ys,xg,yg)?"OK":"NG";
		//cout<<"after"<<endl;
		//print();
		cout<<ans<<endl;
	}

	return 0;
}