#include <iostream>
#include <queue>

using namespace std;

bool bfs(pair<int,int>[],int **);

int main(void){
	int w,h,xs,ys,xg,yg,n,**board,dr[2][2]={4,2,2,4};
	pair<int,int> sg[2];

	do{
		cin >> w >> h >> xs >> ys >> xg >> yg >> n;

		sg[0] = make_pair(xs,ys);
		sg[1] = make_pair(xg,yg);

		board = new int*[w+2];
		for(int i=0;i<w+2;i++)
			board[i] = new int[h+2];

		for(int i=0;i<h+2;i++)
			for(int j=0;j<w+2;j++)
				board[j][i]=0;

		for(int i=0;i<n;i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			for(int j=0;j<dr[d][0];j++)
				for(int k=0;k<dr[d][1];k++)
					board[x+j][y+k]=c;
		}

		cout << (bfs(sg,board)?"OK":"NG");
		cout << endl;

		for(int i=0;i<w+2;i++)
			delete [] board[i];
		delete [] board;	
	}while(w!=0||h!=0);

	return 0;
}

bool bfs(pair<int,int> sg[],int **board){
	queue<pair<int,int>> Q;
	pair<int,int> cur;
	int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1},c;

	Q.push(sg[0]);
	cur=Q.front();
	c=board[cur.first][cur.second];

	while(!Q.empty()&&c!=0){
		cur=Q.front();
		Q.pop();
		board[cur.first][cur.second]=0;

		if(cur==sg[1])
			return true;

		for(int i=0;i<4;i++)
			for(int j=0;j<4;j++)
				if(board[cur.first+dx[i]][cur.second+dy[j]]==c)
					Q.push(make_pair(cur.first+dx[i],cur.second+dy[j]));

	}
	return false;
}