#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int xs,ys,c,a[105][105],memo[105][105],ans,p,w,h;

int solve(int yg,int xg){

  a[yg][xg] = 0;

  if(xs == xg && ys == yg) return ans = 1;

  else if(yg - 1 > 0 && a[yg-1][xg] == p) solve(yg-1,xg);
  else if(xg - 1 > 0 && a[yg][xg-1] == p) solve(yg,xg-1);
  else if(yg + 1 <= w && a[yg+1][xg] == p) solve(yg+1,xg);
  else if(xg + 1 <= h && a[yg][xg+1] == p) solve(yg,xg+1);
}

int main(){
  int xg,yg,n,d,x,y;

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    memset(a,0,sizeof(a));
    memset(memo,0,sizeof(memo));
    ans = 0;

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

    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;

      if(d == 0){
	for(int i=y;i<y+2;i++){
	  for(int j=x;j<x+4;j++) a[i][j] = c;
	}
      }

      else if(d == 1){
	for(int i=y;i<y+4;i++){
	  for(int j=x;j<x+2;j++) a[i][j] = c;
	}
      }
    }

    p = a[yg][xg];
    solve(yg,xg);

    if(ans == 1)   cout << "OK" << endl;
    else if(ans == 0)cout << "NG" << endl;

  }
}