import Data.List

main = getContents >>= putOut.formatOut.calc.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
  
formatIn :: String -> [[Int]]
formatIn = map (map (read :: String -> Int).words).tail.lines

formatOut :: [[[Int]]] -> String
formatOut s = unlines.intercalate  ([replicate 20 '#']) $map (map ((' ' :).unwords.(map show))) s

calc :: [[Int]] -> [[[Int]]]
calc n = f ((reverse n)++[[]]) [s,s,s,s]
  where s = replicate 3 $replicate 10 (0 :: Int)

f :: [[Int]] -> [[[Int]]] -> [[[Int]]]
f [[]] s = s
f  (n:ns) s = g n $f ns s

g :: [Int] -> [[[Int]]] -> [[[Int]]]
g (a:b:c:d:_) s = replace (replace (replace (room + d) c storey) b build) a s
  where build  = s!!(a-1)
        storey = build!!(b-1)
        room   = storey!!(c-1)
  
replace t n s = (init (fst p)) ++ [t] ++ (snd p)
  where p = splitAt n s