#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
using namespace std;

int main() {
  int n,f=0;
  while(cin>>n, n) {
    if(f) cout<<endl;
    vector< pair<int, string> > v;
    string s;
    int a,b,c;
    for(int i=0; i<n; ++i) {
      cin>>s>>a>>b>>c;
      v.push_back( pair<int,string>(a*3+c,s) );
    }

    stable_sort(v.begin(), v.end());

    for(int i=n-1; i>=0; --i)
      cout<<v[i].second<<","<<v[i].first<<endl;
    f=1;
  }
}