#include <iostream>
using namespace std;

int F[102][102];

void DFS(int x, int y, int c){
      if(F[x][y]!=c)
            return;

      F[x][y] = -1;

      DFS(x+1, y  , c);
      DFS(x  , y+1, c);
      DFS(x-1, y  , c);
      DFS(x  , y-1, c);
}

int main(){
      int w,h, xs,ys, xg,yg, n;
      while(1){
            cin >> w >> h;
            if(w==0)    break;
            cin >> xs >> ys;
            cin >> xg >> yg;
            cin >> n;

            int c, d, x, y;
            for(int i=1; i<=n; i++){
                  cin >> c >> d >> x >> y;
                  if(d==0){
                        for(int fx=x; fx<=x+3; fx++){
                        F[fx][y]   = c;
                        F[fx][y+1] = c;
                        }
                  }
                  else if(d==1){
                        for(int fy=y; fy<=y+3; fy++){
                        F[x][fy]   = c;
                        F[x+1][fy] = c;
                        }
                  }
            }

            DFS(xs, ys, F[x][y]);
            if(F[xg][yg]==-1)
                  cout << "OK" << endl;
            else
                  cout << "NG" << endl;
      }

      return 0;
}

