import Control.Applicative
import Data.Function
import Control.Monad

type Building = [[Int]]

initBuildings :: [Building]
initBuildings = replicate 4 $ replicate 3 $ replicate 10 0

update :: Int -> Int -> Int -> [Int] -> [Int]
update _ _ _ [] = []
update r v i (x:xs) = if i == r
                  then (v + x) : (update r v (i+1) xs)
                  else x : (update r v (i+1) xs)

nextBuilding :: Int -> Int -> Int -> Building -> Building
nextBuilding 1 r v [f1,f2,f3] = [(update r v 1 f1), f2, f3]
nextBuilding 2 r v [f1,f2,f3] = [f1, (update r v 1 f2), f3]
nextBuilding 3 r v [f1,f2,f3] = [f1, f2, (update r v 1 f3)]

next :: Int -> Int -> Int -> Int -> [Building] -> [Building]
next 1 f r v [b1,b2,b3,b4] = [nextBuilding f r v b1, b2, b3, b4]
next 2 f r v [b1,b2,b3,b4] = [b1, nextBuilding f r v b2, b3, b4]
next 3 f r v [b1,b2,b3,b4] = [b1, b2, nextBuilding f r v b3, b4]
next 4 f r v [b1,b2,b3,b4] = [b1, b2, b3, nextBuilding f r v b4]

app :: [[Int]] -> [Building] -> [Building]
app [] bs = bs
app ([b,f,r,v]:xs) bs = app xs $ next b f r v bs

main :: IO ()
main = do
    _ <- getLine
    op <- getContents
    let [b1,b2,b3,b4] = (app (map (map read . words) $ lines op) initBuildings)
    forM_ b1 $ \x -> putStrLn $ " " ++ (unwords $ map show x)
    putStrLn $ replicate 20 '#'
    forM_ b2 $ \x -> putStrLn $ " " ++ (unwords $ map show x)
    putStrLn $ replicate 20 '#'
    forM_ b3 $ \x -> putStrLn $ " " ++ (unwords $ map show x)
    putStrLn $ replicate 20 '#'
    forM_ b4 $ \x -> putStrLn $ " " ++ (unwords $ map show x)
