
import std.stdio, std.algorithm, std.string, std.conv, std.array;

void main() {
  bool first = true;
  int times;
  while((times = readln.chomp.to!int) != 0) {
    if (!first) writeln;
    else first = false;
    
    int[string] points;
    string[] countries;
    foreach(t; 0..times) {
      string name;
      string[] data = readln.chomp.split(" ");
      int[] point = data[1..$].map!(to!(int)).array;
      name = data[0];
      points[name] = point[0] * 3 + point[2] * 1;
      countries ~= name;
    }
    string[] names = points.keys;
    sort!((x, y) => points[x] > points[y])(names);
    foreach(n; names) {
      writeln(n, ",", points[n]);
    }
  }
}