import Control.Monad

main :: IO ()
main = do
  loop 0

loop :: Int -> IO ()
loop count = do
  n <- readLn
  if n == 0
    then return ()
    else do
      sss <- replicateM n getLine
      let ss = map words sss
          ts = map tupleToStr $ scoreSort $ map listToTuple ss
      if count == 0
        then return ()
        else putStrLn ""
      mapM_ putStrLn ts
      loop (count+1)

listToTuple :: [String] -> (String,Int)
listToTuple [n,w,l,d] = (n,(read w)*3+(read d))

scoreSort :: [(String,Int)] -> [(String,Int)]
scoreSort [] = []
scoreSort ((n,s):xs) = (scoreSort higher) ++ [(n,s)] ++ (scoreSort lower)
  where higher = [t | t <- xs, (snd t) > s]
        lower = [t | t <- xs, (snd t) <= s]

tupleToStr :: (String,Int) -> String
tupleToStr (name,score) = name ++ "," ++ (show score)