#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,string>> P;
    int w,l,d;
    string s;
    rep(i,n){
      cin>>s>>w>>l>>d;
      P.pb(mp(3*w+d,s));
    }
    sort(all(P));
    for(int i=P.size()-1;i>=0;i--){
        cout<<P[i].sec<<','<<P[i].fir<<endl;
    }
  }
  return 0;
}