def winpoints(teams)   #   -> [[team1,point1],[team2,point2], ...]
  tp = teams.map{|team,win,lose,draw| [team, 3*win+1*draw]}
  return tp.sort{|a,b| b[1]<=>a[1]}
end

def main
  if true then
    fh=STDIN
  else
    fh=open("in1_0124.txt")
  end

  first=true
  while true do
    n = fh.gets.chomp.to_i
    break if n==0
    teams = []
    0.upto(n-1){|i|
      teams.push(fh.gets.chomp.split.map{|x| (x=~ /^\d+$/) ? x.to_i : x})
    }
    if first then
      first=false
    else
      puts
    end
    winpoints(teams).each{|team,points|
      printf("%s,%d\n", team, points)
    }
  end

end

if $0 == __FILE__ then
  main
end