ans = []
loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map do |i|
        name, w, l, d = gets.chomp.split
        [name, [w.to_i*3 + d.to_i, -i]]
    end
    a.sort_by!(&:last).reverse!
    ans << a.map{|name, (point, _)| "#{name},#{point}"}.join("\n")
end
puts ans.join("\n\n")