import Data.List

main =  getLine >>= return . read . head . words >>= 
        sequence . ($ getLine) . replicate >>=
        putStr . moves . map (map read . words)  

moves = unlines . (flip (:) <*> show . length) . 
        map (unwords . map show) . 
        concatMap (zipWith <$> const (++) <*> id <*> tail) .
        concatMap (zipWith <$> const move <*> id <*> tail) . 
        block 2 . map (take 2) .
        filter (odd . last) . squares where


move a@[x0, y0] b@[x1, y1] 
  | a == b    = []
  | x0 == x1  = [[x0, y] | y <- [y0, y0 - signum (y0 - y1)..y1]]
  | y0 == y1  = [[x, y0] | x <- [x0, x0 - signum (x0 - x1)..x1]]
  | otherwise = let vertical = move a [x0, y1] in
                vertical ++ tail (move [x0, y1] b)
    
block n = takeWhile ((== n) . length) . 
          map fst . iterate (splitAt n . snd) . splitAt n 
  
squares = concat . zipWith (map . (:)) [1..] . 
          map (zipWith ((. (: [])) . (:)) [1..])

