import Data.Array.IO
    
main :: IO ()
main = getLine >> getContents >>= kousha . map (map toInt . words) . lines >>=
       getElems >>= putStrLn . init . unlines . format
    where toInt = read :: String -> Int

kousha :: [[Int]] -> IO (IOArray (Int, Int, Int) Int)
kousha [] = newArray ((1,1,1), (4,3,10)) 0
kousha ([b,f,r,v]:xs) = kousha xs >>= (\a -> writeArray a (b,f,r) v >> return a)
  
format :: [Int] -> [String]
format [] = []
format xs = rep f ys 3 10 ++ (if null zs then [] else replicate 20 '#' : format zs)
    where (ys, zs) = splitAt 30 xs
          f = (' ':) . unwords . map show

rep :: ([a] -> b) -> [a] -> Int -> Int -> [b]
rep _ _ _ 0  = []
rep _ [] _ _ = []
rep f xs n l = f ys : rep f zs (n-1) l
    where (ys, zs) = splitAt l xs