#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, i, j;
	char team[10][21] = {0};
	int game[10][3] = {0};
	int point[10] = {0};
	char temp1[21] = {0};
	int temp2;

	while (scanf("%d%*c", &n) != EOF)
	{
		if (n == 0)
			break;

		for (i = 0; i < n; i++)
		{
			scanf("%s %d %d %d%*c", team[i], &game[i][0], &game[i][1], &game[i][2]);
			point[i] = game[i][0] * 3 + game[i][2];
		}

		for (j = 0; j < n - 1; j++)
			for (i = 0; i < n - 1; i++)
				if (point[i] < point[i+1])
				{
					strcpy(temp1, team[i]);
					strcpy(team[i], team[i+1]);
					strcpy(team[i+1], temp1);

					temp2 = point[i];
					point[i] = point[i+1];
					point[i+1] = temp2;
				}

		for (i = 0; i < n; i++)
			printf("%s,%d\n", team[i], point[i]);
	}

	return 0;
}