main = do
  n_ <- getLine
  let 
    n = read $ head $ words n_ :: Int
    house = house_ 12 []
    house_ n ls
      | n > 0     = floor : house_ (n-1) ls
      | otherwise = ls
    floor = floor_ 10 []
    floor_ n ls 
      | n > 0     = 0 : floor_ (n-1) ls
      | otherwise = ls
    showh house = showh_ house 1
    showh_ house n 
      | house == []                = ""
      | (mod n 3) == 0 && n /= 12  = " " ++ (unwords $ map show $ head house) ++ "\n####################\n" ++ (showh_ (tail house) (n+1))
      | otherwise                  = " " ++ (unwords $ map show $ head house) ++ "\n" ++ (showh_ (tail house) (n+1))
    func n house =
      if n > 0 
        then do
          line <- getLine
          let
            [b,f,s,r] = map read $ words line :: [Int]
            enter house b f s r
              | b > 1     = enter house 1 (f+(b-1)*3) s r
              | f > 1     = head house : enter (tail house) b (f-1) s r
              | otherwise = (enter_ (head house) s r) : tail house
            enter_ bldg s r
              | s > 1     = head bldg : enter_ (tail bldg) (s-1) r
              | otherwise = (head bldg) + r : tail bldg
            in
              func (n-1) (enter house b f s r)
        else do
          putStr $ showh house
    in
      func n house

