#include<cstdio>
#include<queue>
using namespace std;
struct Block
{
	int color;
	int angle;
	int x,y;
};
int main(void)
{
	
	
RE:
	queue<pair<int,int> > que;
	int **board;
	int board_mx,board_my;
	int start_x,start_y;
	int goal_x,goal_y;
	int block_num;
	Block *block;
	//
	scanf("%d %d",&board_mx,&board_my);
	if(board_mx==0&&board_my==0)
	{
		goto END;
	}
	board=new int*[board_my];
	for(int f1=0;f1<board_my;f1++)
	{
		board[f1]=new int[board_mx];
		for(int f2=0;f2<board_mx;f2++)
		{
			board[f1][f2]=0;
		}
	}
	scanf("%d %d",&start_x,&start_y);
	scanf("%d %d",&goal_x,&goal_y);
	scanf("%d",&block_num);
	block=new Block[block_num];
	for(int f1=0;f1<block_num;f1++)
	{
		scanf("%d %d %d %d",&block[f1].color,&block[f1].angle,&block[f1].x,&block[f1].y);
		block[f1].x--;
		block[f1].y--;
	}
	//
	for(int f1=0;f1<block_num;f1++)
	{
		//横
		if(!block[f1].angle)
		{
			for(int f2=0;f2<2;f2++)
			{
				for(int f3=0;f3<4;f3++)
				{
					board[block[f1].y+f2][block[f1].x+f3]=block[f1].color;
				}
			}
		}
		//縦
		else
		{
			for(int f2=0;f2<4;f2++)
			{
				for(int f3=0;f3<2;f3++)
				{
					board[block[f1].y+f2][block[f1].x+f3]=block[f1].color;
				}
			}
		}
	}
	/*
	for(int f1=0;f1<board_my;f1++)
	{
		for(int f2=0;f2<board_mx;f2++)
		{
			printf("%d",board[f1][f2]);
		}
		printf("\n");
	}
	*/
	int st_col=board[start_y-1][start_x-1];
	int goal_col=board[goal_y-1][goal_x-1];
	//
	if(st_col!=goal_col||st_col==0||goal_col==0)
	{
		printf("NG\n");
		goto RE;
	}
	//queue<pair<int,int> > que;
	que.push(make_pair(start_y,start_x));
	while(!que.empty())
	{
		pair<int,int> buf=que.front();que.pop();
		if(buf.first==goal_y-1&&buf.second==goal_x-1)
		{
			printf("OK\n");
			goto RE;
		}
		//printf("%d %d\n",buf.second,buf.first);
		board[buf.first][buf.second]=9;
		if(buf.first+1<board_my)
		{
			if(board[buf.first+1][buf.second]==st_col)
			{
				que.push(make_pair(buf.first+1,buf.second));
			}
		}
		if(buf.first-1>=0)
		{
			if(board[buf.first-1][buf.second]==st_col)
			{
				que.push(make_pair(buf.first-1,buf.second));
			}
		}
		if(buf.second+1<board_mx)
		{
			if(board[buf.first][buf.second+1]==st_col)
			{
				que.push(make_pair(buf.first,buf.second+1));
			}
		}
		if(buf.second-1>=0){
			if(board[buf.first][buf.second-1]==st_col)
			{
				que.push(make_pair(buf.first,buf.second-1));
			}
		}
	}
	/*
	for(int f1=0;f1<board_my;f1++)
	{
		for(int f2=0;f2<board_mx;f2++)
		{
			printf("%d",board[f1][f2]);
		}
		printf("\n");
	}
	*/
	printf("NG\n");
END:
	/*
	printf("end\n");
	fflush(stdin);
	getchar();
	*/
	return 0;
}