import Data.List

main = getContents >>= putStrLn.solve.parseInput.tail.lines
  where
    buildingSep = replicate 20 '#'
    floorSep = "\n"
    space = ' '
    parseInput = map (map read . words)
    solve input = intercalate floorSep . intersperse buildingSep $ buildings
      where
        buildings = [intercalate floorSep $ floors b | b <- [1..4]]
        floors b = [space:(unwords $ rooms b f) | f <- [1..3]]
        rooms b f = [show $ numPersons b f r input | r <- [1..10]]
        numPersons b f r input = numPersons' b f r 0 input
        numPersons' _ _ _ acc [] = acc
        numPersons' b f r acc ([xb, xf, xr, xv]:xs)
          | b == xb && f == xf && r == xr = numPersons' b f r (acc + xv) xs
          | otherwise = numPersons' b f r acc xs


