import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  println {
    Iterator.continually(readInt).takeWhile(_!=0).map { n =>
      { for(i<-1 to n) yield {
          val t = readLine.split(" ")
          (t(0),t(1).toInt*3 + t(3).toInt*1)
        }
      }.sortWith( _._2 > _._2).map{ e => e._1 + "," + e._2 }.mkString("\n")
    }.mkString("\n\n")
  }
}