flag=false
loop do
  n= gets.to_i
  break if n==0
  puts if flag
  hash = Hash.new
  n.times do
    key,w,l,d=gets.split
    hash[key]=3*w.to_i+d.to_i
  end
  hash.keys.sort{|a,b| hash[b]-hash[a]}.each do |key|
    print key,",",hash[key],"\n"
  end
  flag = true
end