








#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<utility>
#include<vector>
#include<functional>

using namespace std;



int main(void)
{
	//入力変数
	pair<int, string>h_input[10];
	//いくつ入力するか
	int n = 0;
	//入力変数
	char str_input[100] = {NULL};

	bool flag = false;

	while (cin >> n && n != 0)
	{
		if (flag == true)
		{
			cout << endl;
		}

		flag = true;

		//入力変数
		pair<int , pair<int , int> > tokuten;

		for (int i = 0; i < n; i++)
		{
			cin >> str_input;
			h_input[i].second = str_input;
			cin >> tokuten.first >> tokuten.second.first >> tokuten.second.second;
			//勝ちと負けの分だけ加算
			h_input[i].first = tokuten.first * 3 + tokuten.second.second;
		}

		stable_sort(h_input , h_input + n , greater<pair<int , string> >());

		for (int i = 0; i < n; i++)
		{
			cout << h_input[i].second << "," << h_input[i].first << endl;
		}
	
	}
	
	return 0;
}