#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class T{
  public:
    char c;
    int a, b, n;
    T(){ a = 0; b = 0; }
    bool operator < (const T &t) const {
      if(a != t.a) return a > t.a;
      if(b != t.b) return b < t.b;
      return n < t.n;
    }
};

int main() {
  int N;
  while(cin >>N && N){
    vector<T> ts(N);
    REP(i, N){
      char c; cin >>c; ts[i].c = c; ts[i].n = i;
      REP(j, N - 1){
        int n; cin >>n;
        if(n == 0) ++ts[i].a;
        if(n == 1) ++ts[i].b;
      }
    }
    SORT(ts);
    REP(i, N) cout <<ts[i].c <<endl;
  }

  
  return 0;
}