#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<pair<string,int> > s;
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int w,l,d;cin>>w>>l>>d;
      s.push_back(make_pair(str,w*3+d));
    }
    sort(s.begin(),s.end());
    for(int i=n-1;i>=0;i--)
      cout<<s[i].first<<","<<s[i].second<<endl<<endl;;
  }
  return 0;
}