import Control.Applicative
import Control.Monad
import Data.List (sortBy,intersperse)
data TeamResult = TR { name :: String
                     , win :: Int
                     , lose :: Int
                     , draw :: Int
                     , point :: Int
                     }

main = do
    n <- readLn
    showLeagues n

showLeagues :: Int -> IO ()
showLeagues 0 = return ()
showLeagues n = do
    teams <- replicateM n (team.words<$>getLine)
    mapM_ putStrLn $ map (concat.intersperse ",".(\tr -> [name tr, show.point $ tr])).ordTeams.map calcWinPoint $ teams
    n <- readLn
    unless (n==0) $ putStrLn "" >> showLeagues n


team :: [String] -> TeamResult
team [n,w,l,d] = TR n (read w) (read l) (read d) 0

calcWinPoint :: TeamResult -> TeamResult
calcWinPoint tr = tr { point = (win tr)*3 + (draw tr) }

ordTeams :: [TeamResult] -> [TeamResult]
ordTeams = sortBy (flip ordByWinPoint).map calcWinPoint

ordByWinPoint :: TeamResult -> TeamResult -> Ordering
ordByWinPoint tr1 tr2 = point tr1 `compare` point tr2

