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

int main(void)
{
	//チームの名前
	char str_name[10][21];
	//点数配列
	int h_point[10] = {0};
	//勝ち、負け、引き分けの入力変数
	int win = 0 , loss = 0 , drow = 0;
	//入力数
	int n = 0;
	int i = 0 , j = 0;
	//１番大きい要素を取り出す
	int index = 0;
	//最大値の設定変数
	int max = 0;
	//入れ替える文字列
	char str_tmp[11];
	int team = 0;
	//アクセス順配列
	int h_zyunban[10] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9};

	while (true)
	{
		//参加チーム
		scanf("%d" , &team);

		if (team == 0)
		{
			return 0;
		}

		for (int i = 0; i < team; i++)
		{
			//名前と得点の読み込み
			scanf("%s %d %d %d", str_name[i] , &win , &loss , &drow);
			h_point[i] = win * 3 + drow;
		}

		//ソート
		for (int i = 0; i < team - 1; i++)
		{
			for (int j = i + 1; j < team; j++)
			{
				if (h_point[i] < h_point[j])
				{
					//交換
					int tmp = h_zyunban[i];
					h_zyunban[i] = h_zyunban[j];
					h_zyunban[j] = tmp;

					tmp = h_point[i];
					h_point[i] = h_point[j];
					h_point[j] = tmp;
				}
			}
		}

		//出力
		for (int i = 0; i < team; i++)
		{
			printf("%s,%d\n" , str_name[h_zyunban[i]] , h_point[i]);
		}

		for (int i = 0; i < 10; i++)
		{
			h_zyunban[i] = i;
		}
	}
}