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

typedef std::pair<int, std::string> P;

int n;
std::vector<P> v;

int main()
{
	bool fst = true;

	while( std::cin >> n, n )
	{
		v.clear();

		for( int i = 0; i != n; ++i )
		{
			std::string s;
			int a, b, c;
			std::cin >> s >> a >> b >> c;
			
			v.push_back( P( a * 3 + c, s ) );
		}

		std::stable_sort( v.rbegin(), v.rend() );

		if( !fst )
			std::cout << std::endl;
		for( int i = 0; i != n; ++i )
			std::cout << v[i].second << ',' << v[i].first << std::endl;
	
		fst = false;
	}

	return 0;
}