import Data.List

main = interact $ unlines . map (show' . patrol . map words) . splitBy (== "0 0") . lines
 where show' p = if p then "OK" else "NG"

patrol = all even . map length . group . sort . concat . (["1","2"]:)

splitBy p xs
 | null xs = []
 | p (head xs) = splitBy p (tail xs)
 | otherwise = (takeWhile (not.p) xs : splitBy p (dropWhile (not.p) xs))