/*
	2013 08 01
	Miyagi Technical High School
	J1 JK club Taiki F Watanabe
*/

#include<stdio.h>

typedef struct INFO_TEAM
{
	// チーム名
	char name[21];
	
	// 勝の数
	int win;
	// 負の数
	int lose;
	// 引分の数
	int draw;
	// 成績
	int points;
}INFO;

int main(void)
{
	int i = 0, j = 0, num = 0;
	INFO tmp;
	INFO team[10];
	
	while(1)
	{

		scanf("%d", &num);

		if(num == 0)
		{
			break;
		}

		for(i = 0; i < num; i++)
		{
			scanf("%s %d %d %d", &team[i].name, &team[i].win, &team[i].lose, &team[i].draw);

			team[i].points = 0;

			team[i].points += team[i].win * 3;
			team[i].points += team[i].draw;
		}

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[i].points > team[j].points)
				{
					tmp = team[i];
					team[i] = team[j];
					team[j] = tmp;
				}
			}
		}

		for(i = 0; i < num; i++)
		{
			printf("%s,%d\n", team[i].name, team[i].points);
		}

		putchar('\n');
	}

	return 0;
}