import Data.List

main = getContents >>= putStr.unlines.intersperse (replicate 20 '#').map (init.unlines.map (unwords.map show).(j 10)).j 30.foldl' f (replicate 120 0).map (g.map read.words).tail.lines
    where g [x1,x2,x3,n] = ( (x1-1)*30 + (x2-1)*10 + x3 - 1, (+n) ) 
          f ys (n,p) = take n ys ++ [p (ys!!n)] ++ drop (n+1) ys
          j n [] = []
          j n xs = [take n xs] ++ (j n $ drop n xs)