#include<iostream>
using namespace std;

int Array[200][200];
bool is_goal = false;
#define START 20
#define GOAL 30

void DFS(int h,int w,int c){

  if(Array[h][w] = START){
    DFS(h-1,w,Array[h-1][w]);
    DFS(h,w+1,Array[h][w+1]);
    DFS(h+1,w,Array[h+1][w]);
    DFS(h,w-1,Array[h][w-1]);
  }

  if(!is_goal){

    if(Array[h][w] == GOAL){
      is_goal = true;
      return;
    }

    if(Array[h][w] != c || Array[h][w] == '.'){
      return;
    }

    char tmp=Array[h][w];

    Array[h][w] = '.';

    DFS(h-1,w,tmp);
    DFS(h,w+1,tmp);
    DFS(h+1,w,tmp);
    DFS(h,w-1,tmp);
  }

}

int main(){

    while(1){
      int H,W;
      int Start[2],Goal[2];
      int BlockNum;
      int color,dir,xpos,ypos;

      cin >> H >> W;

      if(H == 0 && W == 0){
        break;
      }

      cin >> Start[0] >> Start[1];
      Array[Start[0]][Start[1]] = START;

      cin >> Goal[0] >> Goal[1];
      Array[Goal[0]][Goal[1]] = GOAL;

      cin >> BlockNum;

      for(int i=0;i<BlockNum;i++){
        cin >> color >> dir >> xpos >> ypos;
        for(int i=0;i<4;i++){
          for(int j=0;j<2;j++){
            if(!dir){//?¨?
              Array[xpos+i][ypos+j] = color;
            }
            else{
              Array[xpos+j][ypos+i] = color;
            }
          }
        }
      }
      DFS(Start[0],Start[1],Array[Start[0]][Start[1]]);

      if(is_goal){
        cout << "OK" << endl;
      }
      else{
        cout << "NG" << endl;
      }
  }
    return 0;
}