f = true
loop do
  n = gets.to_i
  break if n.zero?
  puts unless f
  f = false
  n.times.map {|i|
    c, *xs = gets.split
    w, l, d = xs.map(&:to_i)
    [3 * w + 0 * l + 1 * d, -i, c]
  }.sort.reverse.each {|p, _, c| puts "#{c},#{p}" }
end