import Control.Monad
import Data.List

type Query = ((Int, Int, Int), Int)

toQuery :: [Int] -> Query
toQuery [b, f, r, v] = ((b, f, r), v)

getQuery :: IO Query
getQuery = fmap (toQuery . map read . words) getLine

sumPersons :: Int -> Int -> Int -> [Query] -> Int
sumPersons b f r list = sum [v | (k, v) <- list, k == (b, f, r)]

mkBuildings :: [Query] -> [String]
mkBuildings queries =
  intercalate [replicate 20 '#'] (buildings queries)
  where
    buildings q = [building q b | b <- [1..4]]
    building q b = [floor q b f | f <- [1..3]]
    floor q b f = concat [room q b f r | r <- [1..10]]
    room q b f r = ' ' : (show $ sumPersons b f r q)
main = do
  n <- readLn :: IO Int
  queries <- replicateM n getQuery
  let buildings = mkBuildings queries
  mapM_ putStrLn buildings
  