import Control.Applicative
import Data.List

main = do _ <- getLine
          xs <- map ((map read).words) . lines <$> getContents
          putStr . toOut $ solve xs initialState

toOut :: [[[Int]]] -> String
toOut ys = concatMap unlines . intersperse ["####################"] . map (map (concatMap (" " ++))) $ map (map (map show)) ys

solve :: [[Int]] -> [[[Int]]] -> [[[Int]]]
solve [] st = st
solve (x:xs) st = solve xs (changeSt x st)

changeSt :: [Int] -> [[[Int]]] -> [[[Int]]]
changeSt (b:f:r:v:_) st = makeSt b f st . changeLine r v $ specificLine b f st

specificLine :: Int -> Int -> [[[Int]]] -> [Int]
specificLine b f st = (st !! (b-1)) !! (f-1)

changeLine :: Int -> Int -> [Int] -> [Int]
changeLine r v line = bf ++ (n + v) : af
                      where bf = take (r-1) line
                            af = drop r line
                            n = line !! (r-1)

makeSt :: Int -> Int -> [[[Int]]] -> [Int] -> [[[Int]]]
makeSt b f st line = bfB ++ block : afB
                     where bfB = take (b-1) st
                           afB = drop b st
                           block = bf ++ line : af
                                   where bf = take (f-1) (st !! (b-1))
                                         af = drop f (st !! (b-1))

initialState :: [[[Int]]]
initialState = replicate 4 . replicate 3 $ replicate 10 0