#include<iostream>
#include<queue>
#include<list>

typedef struct block
{
	int x;
	int y;
	int h;
	int w;
	int color;
}block;

block blocks[1280];

std::queue<int> que;
std::list< std::pair<int,int> > adjacive;

void makelist(int n);
bool BFS(int start,int goal);

int main()
{
	int n,w,h,xs,ys,xg,yg,start,goal;
	while(1)
	{
		std::cin>>w>>h;
		if(w==0&&h==0)break;
		std::cin>>xs>>ys>>xg>>yg>>n;
		for(int i=0;i<n;i++)
		{
			int c,d,x,y;
			std::cin>>c>>d>>x>>y;
			blocks[i].color=c;
			blocks[i].x=x;
			blocks[i].y=y;
			if(d==0)
			{
				blocks[i].h=2;
				blocks[i].w=4;
			}
			else
			{
				blocks[i].h=4;
				blocks[i].w=2;
			}
			if(blocks[i].x<=xs&&blocks[i].x+blocks[i].w>=xs&&blocks[i].y<=ys&&blocks[i].y+blocks[i].h>=ys)
			{
				start=i;
			}
			else if(blocks[i].x<=xg&&blocks[i].x+blocks[i].w>=xg&&blocks[i].y<=yg&&blocks[i].y+blocks[i].h>=yg)
			{
				goal=i;
			}
		}
		makelist(n);
		if(BFS(start,goal))
		{
			std::cout<<"OK"<<std::endl;
		}
		else
		{
			std::cout<<"NG"<<std::endl;
		}
	}
	return 0;
}

void makelist(int n)
{
#define x1 blocks[i].x
#define y1 blocks[i].y
#define h1 blocks[i].h
#define w1 blocks[i].w
#define x2 blocks[j].x
#define y2 blocks[j].y
#define h2 blocks[j].h
#define w2 blocks[j].w

	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(blocks[i].color==blocks[j].color)
			{
				if((x1==x2+w2&&y1<=y2+h2&&y1+h1>=y2)||(x2==x1+w1&&y1<=y2+h2&&y1+h1>=y2)||(y1==y2+h2&&x1<=x2+w2&&x1+w1>=x2)||(y2==y1+h1&&x1<=x2+w2&&x2<=x1+w1))
				{
					adjacive.push_back(std::pair<int ,int>(i,j));
				}
			}
		}
	}
}

bool BFS(int start,int goal)
{
	int survey;
	que.push(start);
	
	
	while(!que.empty())
	{
		survey=que.front();
		que.pop();
		for(std::list< std::pair<int,int> >::iterator it=adjacive.begin();it!=adjacive.end();it++)
		{
			if(it->first==survey)
			{
				que.push(it->second);
			}
		}
		if(survey==goal)
		{
			return true;
		}
	}
	return false;
}