#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct P{
    string team;
    int judge[30];
    int win,lose;
    static bool less(const P& left,const P& right){ return left.lose < right.lose; }
    static bool more(const P& le,const P& ri){ return le.win > ri.win; }
};

int main(){
    int n;
    P tmp;
    while(cin >> n,n){
        vector <P> data;
        for(int i=0;i<n;i++){
            tmp.win = 0;
            tmp.lose = 0;
            data.push_back(tmp);
        }
        for(int i=0;i<n;i++){
            cin >> data[i].team;
            for(int j=0;j<n-1;j++){
                cin >> data[i].judge[j];
                if(data[i].judge[j] == 1) data[i].lose++;
                else if(data[i].judge[j] == 0) data[i].win++;
            }
        }
        sort(data.begin(),data.end(),P::less);
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<n;i++) cout << data[i].team << endl;
    }
}