#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct team {
  string name;
  int win;
  int lose;
};

class winner {
public:
  bool operator() (const team& a, const team& b) {
    if(a.win != b.win) {
    return a.win > b.win;
    }
    else {
      return a.lose > b.lose;
    }
  }
};

vector<team> T;

int main() {
  int n,res;
  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      team temp;
      temp.win = 0;temp.lose = 0;
      cin >> temp.name;
      for(int j=0;j<n-1;j++) {
        cin >> res;
        if(res == 0) temp.win++;
        if(res == 1) temp.lose--;
        if(res == 2) continue;
      }
      //      cout << temp.name << " " << temp.win << " " << temp.lose << endl;
      T.push_back(temp);
    }

    sort(T.begin(),T.end(), winner());
    for(int i=0;i<n;i++) {
      cout << T[i].name << endl;
      }
    T.clear();
  }
}