#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define repeat(n, i) for(int i=0; i<(n); i++)
int w, h;
int xs, ys;
int xg, yg;
int n;

int st_color;

int board[300][300];

#define VISITED 6

bool get_input() {
    memset(board, 0, sizeof(board));
    cin >> w >> h;
    if (w == 0 && h == 0) return false;
//    board.resize(h);
//    repeat(h, i) board[i].resize(w);
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    repeat(n, i) {
        int c, d, x, y;
        cin >> c >> d >> x >> y;
        if (d == 1) {
            for (int j = y-1; j < y-1+4; j++) {
                for (int k = x-1; k < x-1+2; k++) {
                    board[j][k] = c;
                }
            }
        } else {
            for (int j = y-1; j < y-1+2; j++) {
                for (int k = x-1; k < x-1+4; k++) {
                    board[j][k] = c;
                }
            }
        }
    }
    st_color = board[ys-1][xs-1];
    return true;
}

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

bool possible;
void dfs(int x, int y) {
    board[y-1][x-1] = VISITED;
    if (x == xg && y == yg) {
        possible = true;
        return;
    }
    repeat(4, i) {
        int nx = x+dx[i], ny = y+dy[i];
        if (1 <= nx && nx <= w && 1 <= ny && ny <= h) {
            if (board[ny-1][nx-1] == st_color) {
                dfs(nx, ny);
            }
        }
    }
}

// debug 
//void solve() {
//    repeat(h, i) {
//        repeat(w, j) {
//            cout << board[i][j] << ' ';
//        }
//        cout << endl;
//    }
//}

void solve() {
    possible = false; dfs(xs, ys);
    if (possible) cout << "OK" << endl;
    else cout << "NG" << endl;
}

int main() {
    while (get_input()) {
        solve();
    }
    return 0;
}
#include <iostream>
#include <string>
using namespace std;

string ans;
int w,h,gx,gy;
int map[110][110];
int dx_[4] = {0,1,0,-1};
int dy_[4] = {1,0,-1,0};
int dx[2][8] = {
	{0,1,2,3,0,1,2,3},
	{0,1,0,1,0,1,0,1}
};
int dy[2][8] = {
	{0,0,0,0,1,1,1,1},
	{0,0,1,1,2,2,3,3},
};
void solve(int x,int y,int color){
	if( ans == "OK" || color == 0 /*|| map[y][x] != color*/ ) return;
	//if( x<0 || x>w || y<0 || y>h ) return;

	for(int i=0 ; i<4 ; ++i ){
		int mx = x + dx_[i];
		int my = y + dy_[i];
		if( mx<0 || mx>w || my<0 || my>h ) continue;
		//cout << "x:" << x << " y:" << y << endl;
		
		if( map[my][mx] == color ){
			if( mx == gx && my == gy ){
				ans = "OK";
			}else{
				map[my][mx] = 0;
				solve( mx , my , color );
			}
		}
	}
}

void debug(){
	char c[6] = {' ','#','$','*','+','@'};
	cout << "w:" << w << " h:" << h << " map : " << endl;
	for(int y=0 ; y<h ; ++y ){
		for(int x=0 ; x<w ; ++x ){
			cout << c[ map[y][x] ];
		}
		cout << endl;
	}
}

int main(){
	int sx,sy,n;
	
	while( cin >> w >> h , w|h ){
		ans = "NG";
		for(int y=0 ; y<110 ; ++y )
			for(int x=0 ; x<110 ; ++x )
				map[y][x] = 0;

		cin >> sx >> sy >> gx >> gy >> n ;
		for(int i=0 ; i<n ; ++i ){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			for(int j=0 ; j<8 ; j++){
				int mx = x + dx[d][j];
				int my = y + dy[d][j];
				map[my][mx] = c;
			}
		}
		//debug();
		//map[sy][sx] = 0;
		solve( sx , sy , map[sy][sx] );
		//cout << "sx:" << sx << " sy:" << sy << endl;
		cout << ans << endl;
	}
}