import Control.Monad
import Data.List
import Text.Printf

indexToMove :: [Int] -> (Int, Int)
indexToMove (b:f:r:v:_) = (((b-1) * 30 + (f-1) * 10 + r), v)

houseMove :: [(Int, Int)] -> [Int] -> [Int]
houseMove [] res = res
houseMove (x:xs) h = let (f, s) = splitAt (fst x) h
                         v = (snd x) + (last f)
                     in houseMove xs ((init f) ++ v:s)

showHouse :: Int -> [Int] -> IO ()
showHouse _ [] = return ()
showHouse n (x:xs) | n `mod` 30 == 0 && n < 120
                                     = do
                                        printf "%2d\n" x
                                        putStrLn . take 20 . repeat $ '#'
                                        showHouse (n+1) xs
                   | n `mod` 10 == 0 = do
                                        printf " %d\n" x
                                        showHouse (n+1) xs
                   | otherwise       = do
                                        printf " %d" x
                                        showHouse (n+1) xs

main = do
    n <- getLine
    ls <- replicateM (read n) getLine
    let move = map (map (read) . words) ls
        moves = map indexToMove move
        houseInit = take 120 . repeat $ 0
        resolve = houseMove moves houseInit
    showHouse 1 resolve