module Main where

import Control.Applicative ((<$>))
import Data.Array

data InputLine = InputLine Int Int Int Int deriving (Read)

nextState (InputLine b f r v) currentState = currentState // [((b,f,r), v + currentState ! (b,f,r))]

prettyShowApart state i = foldl appendToOutput "" [(j,k) | j <- [1..3], k <- [1..10]]
    where appendToOutput str idx = case idx of
            (j, 10) -> str ++ " " ++ (show $ state ! (i, j, 10)) ++ "\n"
            (j, k) -> str ++ " " ++ (show $ state ! (i, j, k))

main = do
    _ <- getLine
    inputStrLines <- lines <$> getContents
    let inputs = map ((read :: String->InputLine) . ((++) "InputLine ")) inputStrLines
    let initState = array ((1,1,1),(4,3,10)) [((b,f,r),0) | b <- [1..4],f <- [1..3], r <- [1..10]]
    let finalState = foldr nextState initState inputs
    putStr $ prettyShowApart finalState 1
    putStrLn "####################"
    putStr $ prettyShowApart finalState 2
    putStrLn "####################"
    putStr $ prettyShowApart finalState 3
    putStrLn "####################"
    putStr $ prettyShowApart finalState 4