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

alias Tuple!(ulong, "win", ulong, "lose") Record;

void main() {
  for(int n; readf("%d\n", &n), n != 0;) {
    Record[string] table;
    int[string] ids;
    for(int i = 0; i < n; i++) {
      string[] line = readln.chomp.split(" ");
      int[] data = line[1..$].map!(to!int).array;
      table[line[0]] = Record(data.filter!(x => x == 0).array.length,
                        data.filter!(x => x == 1).array.length);
      ids[line[0]] = i;
    }
    string[] keys = table.keys;
    sort!((x, y) {
        if (table[x].win != table[y].win) return table[x].win > table[y].win;
        else if (table[x].lose != table[y].lose) return table[x].lose < table[y].lose;
        else return ids[x] < ids[y];
      })(keys);
    foreach(k; keys) writeln(k);
  }
}