#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
struct Data
{
    char name;
    int win;
    int lose;
    bool operator<(const Data& d)const{
        if(win != d.win){
            return win > d.win;
        }
        else{
            return lose < d.lose;
        }
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        Data d[32];
        rep(i,n){
            char team;
            scanf(" %c",&team);
            int w = 0,l = 0;
            rep(j,n-1){
                int x;
                scanf("%d",&x);
                (x == 0) ? ++w : (x == 1) ? ++l :  l+=0;
            }
            d[i].name = team;
            d[i].win = w;
            d[i].lose  = l;
        }
        sort(d,d+n);
        rep(i,n){
            printf("%c\n",d[i].name);
        }
    }
    return 0;
}