using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();
        while (true)
        {
            w = sc.Integer();
            h = sc.Integer();
            if (w == 0 && h == 0)
                break;
            var xs = sc.Integer();
            var ys = sc.Integer();

            xg = sc.Integer();
            yg = sc.Integer();

            var n = sc.Integer();
            board = new int[102, 102];
            for (int i = 0; i < n; i++)
            {
                var c = sc.Integer();
                var d = sc.Integer();
                var x = sc.Integer();
                var y = sc.Integer();
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (d == 0)
                            board[x + j, y + k] = c;
                        else board[x + k, y + j] = c;
                        
                    }
                    
                }
            }
            Program.c = board[xs, ys];
            var b = Solve(xs, ys);
            if(b)  
                Console.WriteLine("OK");
            else
                Console.WriteLine("NG");
        }
    }
    static int[,] board;
    static int w, h, xg, yg, c;
    static int[] dx = { 1, 0, -1, 0 };
    static int[] dy = { 0, 1, 0, -1 };


    static bool Solve(int posx, int posy)
    {
        
        if (board[posx, posy] != c || board[posx,posy]==0)
        {
            return false;
        }
        if (posx == xg && posy == yg)
        {
            return true;
        }
        
        board[posx, posy] = 0;
        
        for (int r = 0; r < 4; r++)
        {
            if (Solve(posx + dx[r], posy + dy[r]))
                return true;
        }
            
        return false;
            
    }
     
}


public class Scanner
{
    readonly TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(TextReader reader = null, string separator = null)
    {
        if (reader == null)
            reader = Console.In;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();
        this.reader = reader;

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToLineEnd()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return int.Parse(this.Scan());
    }
    public double Double()
    {
        return int.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a.ToArray();
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a.ToArray();
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a.ToArray();
    }

}


static public class Repeat
{
    static public void For(this int range, Action<int> action, int start = 0)
    {
        for (int i = start; i < range + start; i++)
            action(i);
    }

    static public IEnumerable<T> Enumerate<T>(this int range, Func<int, T> func, int start = 0)
    {
        for (int i = start; i < range + start; i++)
        {
            yield return func(i);
        }
    }

    static public void ForEach<T>(this IEnumerable<T> source, Action<T> action)
    {
        foreach (var x in source)
            action(x);
    }

}



//*/


Measured memory_bytes: 5708