#include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<int,int> P; 
typedef pair<string,P> PP;
int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
  vector<PP> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(PP(s,P(i,a*3+b*0+c*1)));
    }

    sort(vec.begin(),vec.end(),greater<PP>() );
    //reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S.S << endl;
    }
 
  }
  return 0;
}