import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
  auto n = readln.chomp.to!int;
	while (1) {
    if (!n) break;
    auto team = new string[](n);
    auto score = new int[][](n, 2);
    
    foreach (i; 0..n) {
      auto x = readln.chomp.split.array;
      auto game = x[1..$].map!(to!int);
      score[i][0] = game[0] * 3 + game[2];
      score[i][1] = i;
      team[i] = x[0];
    }

    score = score.sort!((a,b)=>a[0]==b[0]?a[1]<b[1]:a[0]>b[0]).array;
    foreach (i; 0..n) {
      writeln(team[score[i][1]], ",", score[i][0]);
    }
    n = readln.chomp.to!int;
    if (n) writeln("");
  }
}