import Control.Monad
import Data.List

sep = replicate 20 '#'

count b f r i = count' b f r 0 i 
  where
    count' _ _ _ x [] = x
    count' b f r x ([bb, ff, rr, xx]:ii) = count' b f r (if b==bb && f==ff && r==rr then x+xx else x) ii

main = do
    n <- readLn
    info <- fmap (map (map read . words)) $ replicateM n getLine
    putStrLn $ intercalate "\n" $ intersperse sep [intercalate "\n" [unwords [show $ count b f r info | r <- [1..10]] | f <- [1..3]] | b <- [1..4]]
    