include <iostream>
using namespace std;

int F[101][102];

void DFS(int Y, int X, int c) {
        //cout << Y << " " << X << endl;
        if (F[Y][X] != c || F[Y][X] == 0)
                return;
        F[Y][X] = 10;
        DFS(Y - 1, X, c);//???
                                                 //DFS(Y - 1, X+1, A_ito);//??????
        DFS(Y, X + 1, c);//???
                                                 //DFS(Y + 1, X+1, A_ito);//??????
        DFS(Y + 1, X, c);//???
                                                 //DFS(Y + 1, X-1, A_ito);//??????
        DFS(Y, X - 1, c);//???
                                                 //DFS(Y - 1, X-1, A_ito);//??????
}


int main()
{
        int xs, ys, xg, yg, n;
        int c, d, x, y;
        int W = 0, H = 0;

        while (!(W == H == 0)) {
                cin >> W >> H;
                cin >> xs >> ys >> xg >> yg >> n;
                for (int i = 1;i <= n;i++) {
                        cin >> c >> d >> x >> y;
                        if (d == 0) {
                                F[x][y] = c;
                                F[x][y + 1] = c;
                                F[x + 1][y] = c;
                                F[x + 1][y + 1] = c;
                                F[x + 2][y] = c;
                                F[x + 2][y + 1] = c;
                                F[x + 3][y] = c;
                                F[x + 3][y + 1] = c;
                        }
                        if (d == 1) {
                                F[x][y] = c;
                                F[x + 1][y] = c;
                                F[x][y + 1] = c;
                                F[x + 1][y + 1] = c;
                                F[x][y + 2] = c;
                                F[x + 1][y + 2] = c;
                                F[x][y + 3] = c;
                                F[x + 1][y + 3] = c;
                        }
                }
                DFS(ys, xs, F[ys][xs]);

                if (F[yg][xg] == 10) {
                        cout << "OK" << endl;
                }
                else { cout << "NG"<<endl; }
                for (int i = 0;i < H;i++) {
                        for (int j = 0;j < W;j++) {
                                F[i][j] = 0;
                        }
                }
        }

        return 0;
}