import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array

main :: IO ()
main = do
  n <- getl toInt
  xs <- rgetl 10 $ split toInt
  mapM_ printBl $ solve n xs

solve :: Int -> [[Int]] -> [Blur]
solve n xs = findPts $ (iterate (>>= nextCnds) [([],array ((0,0),(9,9)) [((i,j),xs !! i !! j)| i <- [0..9], j <- [0..9]])]) !! n


isDrop :: Array (Int,Int) Int -> Blur -> Bool
isDrop arr (x,y,s)
  | s == 1 = x >= 1 && x <= 8 && y >= 1 && y <= 8 && all (\i -> arr ! i >= 1) sl
  | s == 2 = x >= 1 && x <= 8 && y >= 1 && y <= 8 && all (\i -> arr ! i >= 1) ml
  | s == 3 = x >= 2 && x <= 7 && y >= 2 && y <= 7 && all (\i -> arr ! i >= 1) ll
  | otherwise = False
  where
    sl = [(y-1,x),(y,x-1),(y,x),(y,x+1),(y+1,x)]
    ml = sl ++ [(y-1,x-1),(y-1,x+1),(y+1,x-1),(y+1,x+1)]
    ll = ml ++ [(y-2,x),(y,x-2),(y,x+2),(y+2,x)]

clDrop :: Array (Int,Int) Int -> Blur -> Array (Int,Int) Int
clDrop arr (x,y,s)
  | s == 1 = accum (-) arr sl
  | s == 2 = accum (-) arr ml
  | s == 3 = accum (-) arr ll
  | otherwise = arr
  where
    sl = [((y-1,x),1),((y,x-1),1),((y,x),1),((y,x+1),1),((y+1,x),1)]
    ml = sl ++ [((y-1,x-1),1),((y-1,x+1),1),((y+1,x-1),1),((y+1,x+1),1)]
    ll = ml ++ [((y-2,x),1),((y,x-2),1),((y,x+2),1),((y+2,x),1)]
    
nextCnds :: ([Blur],Array (Int,Int) Int) -> [([Blur],Array (Int,Int) Int)]
nextCnds (bs, arr) = [((x,y,s):bs, clDrop arr (x,y,s))|y <- [1..8], x <- [1..8], s <- [1..3], isDrop arr (x,y,s)]

findPts :: [([Blur],Array (Int,Int) Int)] -> [Blur]
findPts [] = []
findPts ((pts,arr):xs)
  | sum (elems arr) == 0 = pts
  | otherwise = findPts xs

printBl :: Blur -> IO ()
printBl (x,y,s) = putStrLn $ show x ++ " " ++ show y ++ " " ++ show s

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine

type Blur = (Int,Int,Int)