module Main where
 
import Control.Applicative
import Numeric
import Data.List
 
type House = [Floor]
type Floor = [Room]
type Room  = Int
 
officialHouseInit :: [House]
officialHouseInit = replicate 4 houseInit
 
houseInit :: House
houseInit = replicate 3 floorInit
 
floorInit :: Floor
floorInit = replicate 10 roomInit
 
roomInit :: Room
roomInit = 0
 
showOfficialHouse :: [House] -> String
showOfficialHouse = intercalate (replicate 20 '#' ++ "\n") . map showHouse
 
showHouse :: House -> String
showHouse = unlines . map showFloor
 
showFloor :: Floor -> String
showFloor = concatMap ((' ' :) . showRoom) 
 
showRoom :: Room -> String
showRoom = show
 
main :: IO ()
main = do
  { [n] <- getInts
  ; hs <- loop n officialHouseInit
  ; putStr $ showOfficialHouse hs
  }
 
loop :: Int -> [House] -> IO [House]
loop 0 hs = return hs
loop n hs = do
  { [b,f,r,v] <- getInts
  ; let (fronts, ho : ends) = splitAt (b - 1) hs
  ; let (lows, fl : ups)    = splitAt (f - 1) ho
  ; let (xs, rm : ys)       = splitAt (r - 1) fl
  ; let fl' = xs ++ (rm + v) : ys
  ; let ho' = lows ++ fl' : ups
  ; let hs' = fronts ++ ho' : ends
  ; loop (n-1) hs'
  }
   
--
 
getInts :: IO [Int]
getInts = map read . words <$> getLine
 
putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show
 
getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine
 
putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble
 
showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""

