virgin = true

loop do
  n = gets.to_i
  break if n.zero?
  puts "" unless virgin

  teams = {}
  
  n.times do
    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]
    if teams[score].nil?
      teams[score] = [team]
    else
      teams[score] << team
    end
  end

  teams.sort.reverse.each do |score_teams|
    s = score_teams.first
    score_teams.last.each{ |t| puts "#{t},#{s}"}
  end

  virgin = false if virgin
end