#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

bool solve(vvi& field,int x,int y,int xg,int yg,int c)
{
	if(field[y][x]==0)
		return false;
	if(field[y][x]!=c)
		return false;
	if(x==xg && y==yg)
		return true;
	field[y][x]=-1;
	bool res=0;
	res|=solve(field,x-1,y,xg,yg,c);
	res|=solve(field,x+1,y,xg,yg,c);
	res|=solve(field,x,y-1,xg,yg,c);
	res|=solve(field,x,y+1,xg,yg,c);
	return res;
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		int xs,ys,xg,yg,n; cin>>xs>>ys>>xg>>yg>>n;
		vvi field(110,vi(110));
		rep(k,n){
			int c,d,x,y; cin>>c>>d>>x>>y;
			if(d)
				rep(i,4) rep(j,2)
					field[y+i][x+j]=c;
			else
				rep(i,2) rep(j,4)
					field[y+i][x+j]=c;
		}
		cout<<(solve(field,xs,ys,xg,yg,field[ys][xs])?"OK":"NG")<<endl;
	}
	
	return 0;
}