#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    string s[11];
    map<string, int> score;
    int win[11], lose[11], drow[11];
    for(int i=0; i<n; i++){
      cin >> s[i] >> win[i] >> lose[i] >> drow[i];
      score[s[i]] = win[i]*3+drow[i]*1;
    }

    for(int i=0; i<n; i++){
      int M_score=0, winer=0;
      for(int j=0; j<n; j++){

	if(M_score < score[s[j]]){
	  M_score=score[s[j]];
	  winer=j;
	}

	else if(M_score == score[s[j]]){
	  if(win[winer] < win[j]){
	    M_score=score[s[j]];
	    winer=j;
	  }
	  
	  else if(win[winer]==win[j]){
	    if(drow[winer] < drow[j]){
	      M_score=score[s[j]];
	      winer=j;
	    }

	    else if(drow[winer]==drow[j]){
	      if(lose[winer] < lose[j]){
		M_score=score[s[j]];
		winer=j;
	      }
	    }

	  }
	  
	}
	
      }
      cout << s[winer] << "," << M_score << endl;
      score[s[winer]] = -1;
    }
    cout << endl;
  }
  return 0;
}