import Control.Applicative
import Control.Monad

main = do
   n <- readLn :: IO Int
   movings <- forM [1..n] $ \_ -> do
            ns <- fmap (read :: String -> Int) . words <$> getLine
            return $ Address (ns !! 0) (ns !! 1) (ns !! 2) (ns !! 3)
   let addresses = foldr oneMoving initAddresses movings
   forM_ addresses $ \a -> do
    let t = roomTower a
        f = roomFloor a
        r = roomRoom a
        p = roomPeople a
    if r == 10
        then putStrLn $ " " ++ (show p)
        else putStr   $ " " ++ (show p)
    if t /= 4 && f == 3 && r == 10
        then putStrLn divideStr
        else return ()

oneMoving ::  Address -> [Address] -> [Address]
oneMoving  address preAddresses = foldr updateAddress [] preAddresses
    where updateAddress a acc = if address == a
                                    then (address `plus` a) : acc
                                    else a : acc

divideStr :: String
divideStr = concat . (replicate 20) $ "#"

data Address = Address { roomTower   :: Int
                       , roomFloor   :: Int
                       , roomRoom    :: Int
                       , roomPeople  :: Int
                       } deriving (Show)
instance Eq Address where
    (==) (Address a b c _) (Address w x y _)
        | a == w && b == x && c == y = True
        | otherwise = False

plus :: Address -> Address -> Address
plus a b = Address (roomTower a) (roomFloor a) (roomRoom a) (roomPeople a + roomPeople b)

initAddresses = [
                  Address 1 1 1 0
                , Address 1 1 2 0
                , Address 1 1 3 0
                , Address 1 1 4 0
                , Address 1 1 5 0
                , Address 1 1 6 0
                , Address 1 1 7 0
                , Address 1 1 8 0
                , Address 1 1 9 0
                , Address 1 1 10 0
                , Address 1 2 1 0
                , Address 1 2 2 0
                , Address 1 2 3 0
                , Address 1 2 4 0
                , Address 1 2 5 0
                , Address 1 2 6 0
                , Address 1 2 7 0
                , Address 1 2 8 0
                , Address 1 2 9 0
                , Address 1 2 10 0
                , Address 1 3 1 0
                , Address 1 3 2 0
                , Address 1 3 3 0
                , Address 1 3 4 0
                , Address 1 3 5 0
                , Address 1 3 6 0
                , Address 1 3 7 0
                , Address 1 3 8 0
                , Address 1 3 9 0
                , Address 1 3 10 0
                , Address 2 1 1 0
                , Address 2 1 2 0
                , Address 2 1 3 0
                , Address 2 1 4 0
                , Address 2 1 5 0
                , Address 2 1 6 0
                , Address 2 1 7 0
                , Address 2 1 8 0
                , Address 2 1 9 0
                , Address 2 1 10 0
                , Address 2 2 1 0
                , Address 2 2 2 0
                , Address 2 2 3 0
                , Address 2 2 4 0
                , Address 2 2 5 0
                , Address 2 2 6 0
                , Address 2 2 7 0
                , Address 2 2 8 0
                , Address 2 2 9 0
                , Address 2 2 10 0
                , Address 2 3 1 0
                , Address 2 3 2 0
                , Address 2 3 3 0
                , Address 2 3 4 0
                , Address 2 3 5 0
                , Address 2 3 6 0
                , Address 2 3 7 0
                , Address 2 3 8 0
                , Address 2 3 9 0
                , Address 2 3 10 0
                , Address 3 1 1 0
                , Address 3 1 2 0
                , Address 3 1 3 0
                , Address 3 1 4 0
                , Address 3 1 5 0
                , Address 3 1 6 0
                , Address 3 1 7 0
                , Address 3 1 8 0
                , Address 3 1 9 0
                , Address 3 1 10 0
                , Address 3 2 1 0
                , Address 3 2 2 0
                , Address 3 2 3 0
                , Address 3 2 4 0
                , Address 3 2 5 0
                , Address 3 2 6 0
                , Address 3 2 7 0
                , Address 3 2 8 0
                , Address 3 2 9 0
                , Address 3 2 10 0
                , Address 3 3 1 0
                , Address 3 3 2 0
                , Address 3 3 3 0
                , Address 3 3 4 0
                , Address 3 3 5 0
                , Address 3 3 6 0
                , Address 3 3 7 0
                , Address 3 3 8 0
                , Address 3 3 9 0
                , Address 3 3 10 0
                , Address 4 1 1 0
                , Address 4 1 2 0
                , Address 4 1 3 0
                , Address 4 1 4 0
                , Address 4 1 5 0
                , Address 4 1 6 0
                , Address 4 1 7 0
                , Address 4 1 8 0
                , Address 4 1 9 0
                , Address 4 1 10 0
                , Address 4 2 1 0
                , Address 4 2 2 0
                , Address 4 2 3 0
                , Address 4 2 4 0
                , Address 4 2 5 0
                , Address 4 2 6 0
                , Address 4 2 7 0
                , Address 4 2 8 0
                , Address 4 2 9 0
                , Address 4 2 10 0
                , Address 4 3 1 0
                , Address 4 3 2 0
                , Address 4 3 3 0
                , Address 4 3 4 0
                , Address 4 3 5 0
                , Address 4 3 6 0
                , Address 4 3 7 0
                , Address 4 3 8 0
                , Address 4 3 9 0
                , Address 4 3 10 0
                ]