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

void main() {
  for(int N; N = readln.chomp.to!int, N; ) {
    alias Tuple!(string, "name", int, "win", int, "lose") Team;
    auto v = new Team[N];
    foreach(i; 0 .. N) {
      auto s = readln.split;
      string name = s[0];
      int win = 0, lose = 0;
      foreach(k; s[1 .. N]) {
        int ks = k.to!int;
        if(ks == 0) win++;
        else if(ks == 1) lose++;
      }
      v[i] = tuple(name, win, lose);
    }

    bool comp(Team a, Team b) {
      if(a.win != b.win) return a.win > b.win;
      return a.lose < b.lose;
    }
    sort!(comp)(v);
    foreach(t; v)
      writeln(t.name);
  }
}