#include<iostream>

bool flag;
int n,sx,sy,gx,gy,col;

void erase(int** field){
	for(int i=0; i<102; i++)
		for(int j=0; j<102; j++)
			field[i][j] = 0;
}

void DFS(int x, int y, int** field){
	int xx = x+1;
	int yy = y;

	if(xx == gx && yy == gy){
		flag = true;
		return;
	}

	if(field[yy][xx] == col)
		DFS(xx, yy, field);
	if(flag)
		return;

	xx = x;
	yy = y+1;
	if(field[yy][xx] == col)
		DFS(xx, yy, field);
	if(flag)
		return;

	xx = x-1;
	yy = y;
	if(field[yy][xx] == col)
		DFS(xx, yy, field);
	if(flag)
		return;
			
	xx = x;
	yy = y-1;
	if(field[yy][xx] == col)
		DFS(xx, yy, field);
}

int main(){
	int field[102][102];//y,x
	int c,d,bx,by;
	using std::cin;
	while(true){
		flag = false;
		erase(field);
		cin >> c >> d;
		if(!c && !d)
			return 0;
		cin >> sx >> sy;
		cin >> gx >> gy;
		cin >> n;
		for(int i=0; i<n; i++){
			cin >> c >> d >> bx >> by;
			if(d==0){
				for(int h=by; h<by+2; h++)
					for(int k=bx; k<bx+4; k++)
						field[h][k] = c;
			}
			else{
				for(int h=by; h<by+4; h++)
					for(int k=bx; k<bx+2; k++)
						field[h][k] = c;
			}
		}
		col = field[gy][gx];
		DFS(sx, sy, field);
		if(flag)
			std::cout << "OK\n";
		else
			std::cout << "NG\n";
	}
}