#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int W,H,sx,sy,gx,gy,color;
int dx[8]={0,0,0,0,1,1,1,1},dy[8]={0,1,2,3,0,1,2,3},cx[4]={-1,0,0,1},cy[4]={0,-1,1,0};
vvi field;
vvb used;

bool solve(int x,int y,int color,vvb& used){
	used[x][y]=1;
	if(x==gx&&y==gy) return 1;
	for(int i=0;i<4;i++){
		int tmpx=x+cx[i],tmpy=y+cy[i];
		if(tmpx>=0&&tmpx<W&&tmpy>=0&&tmpy<H&&field[tmpx][tmpy]==color&&!used[tmpx][tmpy]){
			if(solve(tmpx,tmpy,color,used)) return 1;
		}
	}
	return 0;
}

int main(){
	while(1){
		cin>>W>>H;
		if(!W) break;
		field=vvi(H,vi(W,-1));
		cin>>sx>>sy>>gx>>gy;
		sx--;
		sy--;
		gx--;
		gy--;
		int n;
		cin>>n;
		int c,d,x,y;
		for(int i=0;i<n;i++){
			cin>>c>>d>>x>>y;
			x--;
			y--;
			if(d){
				for(int i=0;i<8;i++) field[x+dx[i]][y+dy[i]]=c;
			}
			else{
				for(int i=0;i<8;i++) field[x+dy[i]][y+dx[i]]=c;
			}
		}
		if(field[sx][sy]==-1||field[gx][gy]==-1) cout<<"NG"<<endl;
		else {
			int color=field[sx][sy];
			used=vvb(H,vb(W));
			if(solve(sx,sy,color,used)) cout<<"OK"<<endl;
			else cout<<"NG"<<endl;
		}
	}
}