#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    char name;
    int win;
    int lose;
};

int main(){
    int n;
    struct data data[15];
    while(cin >> n, n){
        rep(i,n){
            cin >> data[i].name;
            data[i].win = data[i].lose = 0;
            rep(j,n - 1){
                int inp;
                cin >> inp;
                if(inp == 0)
                    data[i].win++;
                else if(inp == 1)
                    data[i].lose++;
            }
        }
        rep(i,n){
            rep(j,n - 1){
                if(data[j].win < data[j + 1].win){
                    struct data g = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = g;
                }
                if(data[j].win == data[j + 1].win){
                    if(data[j].lose > data[j + 1].lose){
                        struct data g = data[j];
                        data[j] = data[j + 1];
                        data[j + 1] = g;
                    }
                }
            }
        }
        rep(i,n){
            cout << data[i].name << endl;
        }
    }
}