import           Control.Applicative
import           Control.Monad
import           Data.Array.IO
import           Data.Array.MArray
import           Data.List           (intercalate, sort, splitAt)

kugiri :: String
kugiri = "####################"

createArray :: [[Int]] -> IO (IOUArray (Int, Int, Int) Int)
createArray xss = do
    a <- newArray ((1,1,1), (4,3,10)) 0
    forM_ xss $ \[b,f,r,v] -> do
        n <- readArray a (b,f,r)
        writeArray a (b,f,r) (n + v)
    return a

showArray :: IOUArray (Int, Int, Int) Int -> IO ()
showArray a = do
    es <- getElems a
    let (b1, ss) = splitAt 30 es
    let (b2, ts) = splitAt 30 ss
    let (b3, us) = splitAt 30 ts
    let (b4, _ ) = splitAt 30 us
    showBuilding b1
    putStrLn kugiri
    showBuilding b2
    putStrLn kugiri
    showBuilding b3
    putStrLn kugiri
    showBuilding b4

showBuilding :: [Int] -> IO ()
showBuilding es = do
    let (f1, ss) = splitAt 10 es
    let (f2, ts) = splitAt 10 ss
    let (f3, _ ) = splitAt 10 ts
    putStrLn . (' ':) . intercalate " " $ map show f1
    putStrLn . (' ':) . intercalate " " $ map show f2
    putStrLn . (' ':) . intercalate " " $ map show f3
    return ()

main :: IO ()
main = do
    getLine
    xss <- fmap (fmap read . words) . lines <$> getContents :: IO [[Int]]
    a <- createArray (sort xss)
    showArray a

