#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    while(1){
        int w, h; cin>>w>>h;
        if(w == 0) return 0;

        int sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy;
        sx--, sy--, gx--, gy--;

        int n; cin>>n;
        vector<vector<int>> board(h, vector<int>(w, 0));
        while(n--){
            int c, d, x, y; cin>>c>>d>>x>>y;
            x--, y--;
            if(d == 0){
                for(int i=y; i<=y+1; i++){
                    for(int j=x; j<=x+3; j++){
                        board[i][j] = c;
                    }
                }
            }
            else{
                for(int i=y; i<=y+3; i++){
                    for(int j=x; j<=x+1; j++){
                        board[i][j] = c;
                    }
                }
            }
        }

        queue<P> que;
        que.push(P(sy, sx));
        int color = board[sy][sx];
        board[sy][sx] = 0;
        if(color == 0){
            cout << "NG" << endl;
            continue;
        }

        while(que.size()){
            int cy, cx;
            tie(cy, cx) = que.front();
            que.pop();

            if(cy == gy && cx == gx){
                cout << "OK" << endl;
                goto END;
            }    

            for(int i=0; i<4; i++){
                int ny = cy + dy[i];
                int nx = cx + dx[i];

                if(0 <= ny && ny < h && 0 <= nx && nx < w){
                    if(board[ny][nx] == color){
                        board[ny][nx] = 0;
                        que.push(P(ny, nx));
                    }
                }
            }
        }

        cout << "NG" << endl;
        END:;
    }
}

#include <iostream>
#include<queue>
#include<string.h>
using namespace std;
#define TATE 1
#define YOKO 0

struct ST {
        int x;
        int y;
    };

int main(void){
    int map[101][101];
    int board[101][101];
    int T[]={0,-1,1,0};
    int Y[]={1,0,0,-1};
    int w,h,xs,xg,ys,yg,n,color,muki,x,y;
    
    ST RE;
    ST GO;
    queue <ST> Q;
    while(1){
        memset(map,0,sizeof(map));
        memset(board,0,sizeof(board));
        cin>>w>>h;
        if(w==0&&h==0)break;
        cin>>xs>>ys>>xg>>yg>>n;
        for(int i=0;i<n;i++){
            cin>>color>>muki>>x>>y;
            if(muki==YOKO){
                for(int j=0;j<4;j++){
                    board[y][x+j]=board[y+1][x+j]=color;
                }
            }
            else{
                for(int j=0;j<4;j++){
                    board[y+j][x]=board[y+j][x+1]=color;
                }
            }
        }
       /* for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cout<<board[i][j];
            }
            cout<<endl;
        }*/
        RE.x=xs;
        RE.y=ys;
        map[ys][xs]=1;
        Q.push(RE);
        int flag=0;
        while(!Q.empty()){
            RE=Q.front();
            Q.pop();
            if(RE.x==xg&&RE.y==yg&&board[RE.y][RE.x]==board[yg][xg]){
                flag=1;
                //cout<<RE.x<<" "<<RE.y<<endl;
                break;
            }
            else{
                for(int i=0;i<4;i++){
                    GO=RE;
                    if(GO.x+Y[i]>0&&GO.y+T[i]>0&&GO.x+Y[i]<101&&GO.y+T[i]<101&&board[GO.y+T[i]][GO.x+Y[i]]==board[GO.y][GO.x]&&map[GO.y+T[i]][GO.x+Y[i]]!=1){
                        GO.x+=Y[i];
                        GO.y+=T[i];
                        map[GO.y][GO.x]=1;
                        Q.push(GO);
                    }
                }
            }
        }
       /* for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout<<board[i][j];
            }
            cout<<endl;
        }*/
        if(flag==1){
            cout<<"OK"<<endl;
        }
        else{
            cout<<"NG"<<endl;
        }
    }
    
}

