result = []
while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{|i|
        line = gets.chomp.split
        arr << [line[0], line[1].to_i * 3 + line[3].to_i, i]
    }
    arr2 = []
    arr.sort_by{|item| [-item[1], item[2]]}.each{|name, point, index|  arr2 << sprintf("%s,%d", name, point)}
    result << arr2
end

result.each_with_index{|arr, i|
    puts arr
    puts if i != result.length - 1
}
