loop do
  n = gets.to_i
  break if n.zero?
  teams = []
  
  n.times do |i|
    team_and_score = gets.chomp.split
    team = team_and_score.first
    wld = team_and_score[1..-1].map(&:to_i)
    score = 3*wld[0] + wld[2]
    teams[i] = [team, score]
  end
  teams.sort_by{ |t_s| t_s.last }.reverse.each do |team|
    puts "#{team.first},#{team.last}"
  end
end