import Control.Applicative

type Data = (Int, Int, Int, Int)

type Floor = [Int]

type Building = [Floor]

type Problem = [Data]

type Result = [Building]

calcValue :: Problem -> Int -> Int -> Int -> Int

calcValue xs b f r
    = sum $ [vx | (bx, fx, rx, vx) <- xs, bx == b, fx == f, rx == r]

solve :: Problem -> Result

solve xs
    = [[[calcValue xs b f r | r <- [1..10]] | f <- [1..3]] | b <- [1..4]]

input :: IO Problem

input
    = do
        n <- read <$> getLine
        xs <- inputData n []
        return xs
        
inputData :: Int -> Problem -> IO Problem

inputData 0 xs
    = return xs
    
inputData n xs
    = do
        [b, f, r, v] <- words <$> getLine
        inputData (n - 1) $ (read b, read f, read r, read v) : xs
    
output :: Result -> IO ()

output xs
    = putStr $ concat $ init $ concat [[out] ++ [separate] | out <- [outputBuilding b | b <- xs]]
    
outputBuilding :: Building -> String

outputBuilding b
    = concat [concat [" " ++ show r | r <- f] ++ "\n" | f <- b]
    
separate :: String

separate
    = replicate 20 '#' ++ "\n" 
    
main :: IO ()

main = output =<< solve <$> input