#include <iostream>
#include <cstdio>
using namespace std;
typedef struct{
  int ans;
  char s[1111];
}Team;

int comp( const void *c1, const void *c2 );

Team team[11111];
int main(){
  int n;
  int flag=0;
  int a,b,c;
  while(1){
    cin >> n;
    if(n==0)break;
    cout << endl;
    /*if(flag==1){
      cout << endl;
      }*/
    flag=1;
    for(int i=0;i<n;i++){
      cin >> team[i].s >> a >> b >> c;
      team[i].ans=a*3 + c;
    }
    qsort( team, n, sizeof(Team), comp );
    for(int i=0;i<n;i++){
      cout << team[i].s << "," << team[i].ans << endl;
    }
  }
}

/* 比較関数 */
int comp( const void *c1, const void *c2 )
{
  Team test1 = *(Team *)c1;
  Team test2 = *(Team *)c2;
  
  int tmp1 = test1.ans;
  int tmp2 = test2.ans;
  
  return tmp2 - tmp1;
}