#include <iostream>
#include <queue>

using namespace std;

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

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

	while(true){
		cin >> w >> h;

		if(w==0&&h==0)
			break;

		cin >> xs >> ys >> xg >> yg >> n;

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

		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;

	}

	return 0;
}

bool bfs(pair<int,int> sg[2],int board[102][102]){
	return false;
}