module Main where

import Data.Functor
import Data.List

main :: IO ()
main =  do
 { [n] <- getInts
 ; hs  <- loop n iHouses
 ; putStr $ showHouses hs
 }

loop :: Int -> [House] -> IO [House]
loop 0 hs = return hs
loop n hs = do
  { u <- getInts
  ; loop (n-1) (updateHs u hs)
  }

type House = [[Int]]

showHouse :: House -> [String]
showHouse = map (unwords . map show)

showHouses :: [House] -> String
showHouses = unlines . concat . intersperse [replicate 20 '#'] . map showHouse

iHouses :: [House]
iHouses = replicate 4 iHouse

iHouse :: House
iHouse = replicate 3 (replicate 10 0)

updateH :: [Int] -> House -> House
updateH [b,f,r,v] h = case splitAt (f-1) h of
  (xs,fl:ys) -> case splitAt (r-1) fl of
    (zs,rm:ws) -> xs ++ (zs ++ (rm + v) : ws) : ys

updateHs :: [Int] -> [House] -> [House]
updateHs [b,f,r,v] hs = case splitAt (b-1) hs of
  (xs,h:ys) -> xs ++ updateH [b,f,r,v] h : ys

getInts :: IO [Int]
getInts = map read . words <$> getLine