import Control.Monad
import Data.Array
main = do
  n <- readLn :: IO Int
  bfrv <- replicateM n $ return . map (read :: String->Int) . words =<< getLine
  showArray $ foldr addArray (makeArray [0..]) (map makeArray bfrv)

addArray arr1 arr2 = array ((1,1,1),(4,3,10)) [((b,f,r), (arr1!(b,f,r)) + (arr2!(b,f,r))) |b<-[1..4],f<-[1..3],r<-[1..10]]
makeArray bfrv =  array ((1,1,1),(4,3,10)) [((b',f',r'), if b==b' && f==f' && r==r' then v else 0)|b'<-[1..4],f'<-[1..3],r'<-[1..10]]
  where b:f:r:v:_ = bfrv
showArray arr = do
  forM_ [1..4] $ \b -> do
    forM_ [1..3] $ \f -> do
      putStr " "
      forM_ [1..10] $ \r -> do
        putStr $ show $ arr!(b,f,r)
        putStr $ if r/=10 then " " else ""
      putStrLn ""
    if b==4 then (return ()) else (putStrLn ['#'|i<-[1..20]])
