import qualified Data.Map as M
import Data.List
import Data.Maybe
import Control.Monad

main' = print $ range 3 (0,0)

main = interact $ show' . uncurry blur . read' . lines
 where
  read' (n:xs) = (read n, m)
   where
    ds = map (map read . words) xs
    m = M.fromList [((x,y),d) | x<-[0..9], y<-[0..9], let d = ds!!y!!x, d/=0]
  show' = unlines . map format
   where format ((x,y),d) = unwords (map show [x,y,d])

blur :: Int -> M.Map (Int,Int) Int -> [((Int,Int),Int)]
blur n m = fromJust (dfs n (Just m) [])
 where
  dfs _ Nothing _ = Nothing
  dfs 0 (Just m') t'
   | M.null m' = Just t'
   | otherwise = Nothing
  dfs n' (Just m') t'
   | M.null m' = Nothing
   | otherwise = foldl1' mplus [dfs (n'-1) (try xy d m') ((xy,d):t') | d<-[1,2,3], xy<-xys]
    where xys = M.keys m'

try :: (Int,Int) -> Int -> M.Map (Int,Int) Int -> Maybe (M.Map (Int,Int) Int)
try xy d m
 | all (flip elem (M.keys m)) xys = Just (foldl' (flip (M.update bleach)) m xys)
 | otherwise = Nothing
 where
  xys = filter inborder (range d xy)
  inborder (x,y) = 0<=x && x<=9 && 0<=y && y<=9
  bleach n = if n==1 then Nothing else Just (pred n)
  
range 1 (x,y) = [(x+dx,y+dy) | dx<-[(-1)..1], dy<-[(-1)..1], abs dx + abs dy <= 1]
range 2 (x,y) = [(x+dx,y+dy) | dx<-[(-1)..1], dy<-[(-1)..1]]
range 3 (x,y) = [(x+dx,y+dy) | dx<-[(-2)..2], dy<-[(-2)..2], abs dx + abs dy <= 3]