until (n = gets.to_i) == 0
  result = {}
  n.times do
    team, win, lose, draw = gets.split
    result[team] = win.to_i * 3 + draw.to_i
  end
  i = 0
  result.sort_by {|k, v| [-v, i += 1]}.each {|item| puts item.join(",")}
  puts
end