module Main where
--import Debug.Trace
import Data.List
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [[Int]] -> String
solve notes = toString (iter (listArray ((1,1,1), (4,3,10)) (replicate 120 0)) notes) (range ((1,1,1), (4,3,10))) where
    toString ar = iterS 0 0 where
        iterS _ _ [] = []
        iterS pb pf ((b, f, r):xs)
            | pb == b && pf == f = ' ':show (ar ! (b,f,r)) ++ iterS pb pf xs
            | pb == b && pf /= f = '\n':' ':show (ar ! (b,f,r))++ iterS pb f xs
            | otherwise = '\n':replicate 20 '#' ++ '\n':' ':show (ar ! (b,f,r))++ iterS b f xs
    iter ar [] = ar
    iter ar ([b, f, r, v]:xs) = iter (ar // [((b, f, r), ar ! (b,f,r) + v)]) xs

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readLines :: Int -> IO [[Int]]
readLines 0 = return []
readLines n = readLine >>= (\a -> fmap (a:) (readLines (pred n)))

main :: IO() 
main = do
    [n] <- readLine
    l  <- readLines n
    putStrLn $ drop 21 (solve l)

