#include<iostream>
#include<algorithm>

using namespace std ;

typedef pair< int ,string > pay ;

pay p[ 10 ] ;

int main()
{
	int n ,dr ;
	cin >> n ;
	while( n )
	{
		//pay p[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> p[ i ].second >> p[ i ].first >> dr >> dr ;
			p[ i ].first = p[ i ].first * 3 + dr ;
		}

		sort( p ,p + n ) ;

		for( int i = n - 1 ; i >= 0 ; i-- )
			cout << p[ i ].second << "," << p[ i ].first << endl ;
		if( cin >> n ,n )
			cout << endl ;
	}
	return 0 ;
}