import Data.List

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

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

patrol es = patrol' 1 es
 where
  patrol' 2 [] = True
  patrol' v es = any (\e -> elem v e && patrol' (head (delete v e)) (delete e es)) es