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

Team team[11111];
int main(){
  int n;
  int flag=0;
  int a,b,c;
  while(1){
    cin >> n;
    if(n==0)break;
    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;
    }
    for(int i=0;i<n;i++){
      for(int j=n-1;j>i;j--){
	if(team[i].ans<=team[j].ans){
	  Team tmp=team[i];
	  team[i]=team[j];
	  team[j]=tmp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout << team[i].s << "," << team[i].ans << endl;
    }
  }
}