#include <bits/stdc++.h>
using namespace std;


bool b;

void dfs(const vector<vector<int> >& v ,int x , int y , int w , int h , int xg , int yg , int sc){
	if(x==xg&&y==yg) {b=true;return;}
	for(int i=0;i<4;++i){
		int dx[]={1,0,-1,0};
		int dy[]={0,1,0,-1};
		int tx=x+dx[i];
		int ty=y+dy[i];
		if(tx<=0||ty<=0||tx>w||ty>h) continue;
		if(v[tx][ty]!=sc || v[tx][ty]==0) continue;
		if(b) continue;
		dfs( v , tx,ty,w,h,xg,yg,sc);
	}
}

int main(){
	int w , h;
	while(cin >> w >> h , w||h){
		int xs , ys , xg , yg ;
		int n;
		b=false;
		vector<vector<int> > board(101);
		for(int i=0;i<101;++i) board[i].resize(101);
		cin >> xs >> ys >> xg >> yg >> n;
		for(int i=0;i<n;++i){
			int c , d , x , y;
			cin >> c >> d >> x >> y;
			if(!d){
				for(int k=0;k<2;++k){
					for(int j=0;j<4;++j){
						board[x+j][y+k]=c;
					}
				}
			} else {
				for(int k=0;k<4;++k){
					for(int j=0;j<2;++j){
						board[x+j][y+k]=c;
					}
				}
			}
		}
		
		int sc=board[xs][ys];
		int gc=board[xg][yg];
		if(sc!=gc) {}
		else dfs(board ,xs,ys , w , h , xg , yg , sc);
		cout << ( b ? "OK" : "NG") << endl;
	}
	return 0;
}