#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int gx,gy,sx,sy;
int map[102][102];
bool flag[102][102];
int xx[]={3,1};
int yy[]={1,3};
int xv[]={0,1,0,-1};
int yv[]={1,0,-1,0};
void cal(int X,int Y){
	flag[X][Y]=1;
	for(int i=0;i<4;i++){
		if(map[X][Y]==map[X+xv[i]][Y+yv[i]]&&!flag[X+xv[i]][Y+yv[i]]){
			cal(X+xv[i],Y+yv[i]);
		}
	}
}

int main(){
	for(int w,h,n;cin>>w>>h,w;){
		memset(map,0,sizeof(map));
		memset(flag,0,sizeof(flag));
		cin>>sx>>sy;
		cin>>gx>>gy;
		for(cin>>n;n>0;n--){
			int c,d,x,y;
			cin>>c>>d>>x>>y;
			for(int X=x;X<=x+xx[d];X++){
				for(int Y=y;Y<=y+yy[d];Y++){
					map[X][Y]=c;
				}
			}
		}
		if(map[sx][sy])cal(sx,sy);
		if(flag[gx][gy])cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	
	return 0;
}
