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

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int h,w;
vvint vv;
pii s,g;
vvint used;
int dd[]={1,0,-1,0,1};
bool foo(pii a,int c){
	if(used[a.F][a.S]) return false;
	if(vv[a.F][a.S]!=c) return false;
	used[a.F][a.S]=1;
	if(a==g) return true;
	rep(i,4){
		pii next=a;
		next.F+=dd[i];
		next.S+=dd[i+1];
		if(0<=next.F&&next.F<h&&0<=next.S&&next.S<w){
			if(foo(next,c)) return true;
		}
	}
	return false;
}
void mainmain(){
	while(cin>>w>>h,w||h){
		initvv(vv,h,w,0);
		used=vv;
		cin>>s.S>>s.F>>g.S>>g.F;
		s.F--;s.S--;
		g.F--;g.S--;
		int n;
		cin>>n;
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>d>>c;
			c--;
			d--;
			if(b==0){
				vv[c][d]=vv[c][d+1]=vv[c][d+2]=vv[c][d+3]=a;
				vv[c+1][d]=vv[c+1][d+1]=vv[c+1][d+2]=vv[c+1][d+3]=a;
			}
			else{
				vv[c][d]=vv[c+1][d]=vv[c+2][d]=vv[c+3][d]=a;
				vv[c][d+1]=vv[c+1][d+1]=vv[c+2][d+1]=vv[c+3][d+1]=a;
			}
		}
		rep(i,h){
			rep(j,w){

			}
		}
		if(vv[s.F][s.S]==0){
			cout<<"NG"<<endl;
		}
		else if(foo(s,vv[s.F][s.S])){
			cout<<"OK"<<endl;
		}
		else{
			cout<<"NG"<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}