#include<bits/stdc++.h>
using namespace std;

int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
int block[100][100];
bool put[100][100];
int already[100][100];
int w, h;
int xs, ys;
int xg, yg;
bool dfs(int nex, int ney);

int main(){
  int n;
  
  while(1){
    memset(block, 0, sizeof(block));
    memset(already, 0, sizeof(already));
    memset(put, 0, sizeof(put));
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    for(int i = 0; i < n; i++){
      int c, d, x, y;
      int wide, high;
      cin >> c >> d >> x >> y;
      if(d){
	wide = 2; high = 4;
      }
      else{
	wide = 4; high = 2;
      }
      for(int j = 0; j < high; j++){
	for(int k = 0; k < wide; k++){
	  block[y+j][x+k] = c;
	  put[y+j][x+k] = true;
	}
      }
    }
    bool ans = false;
    if(block[ys][xs] == block[yg][xg]){
      ans = dfs(xs, ys);
      if(ans) cout << "OK" << endl;
      else cout << "NG" << endl;
    }
    else cout << "NG" << endl;
  }
}

bool dfs(int nex, int ney){
  already[nex][ney] = 1;
  if(nex == xg && ney == yg) return true;
  for(int i = 0; i < 4; i++){
    int nx = nex + xx[i];
    int ny = ney + yy[i];
    if(0 <= nx && 0 <= ny && ny < h && nx < w && put[ny][nx] && !already[ny][nx] && block[ys][xs] == block[ny][nx]) return dfs(nx, ny);
  }
  return false;
}