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

struct Team {
    char t;
    int win, lose;
    bool operator < (const Team& team_) const {
        return win == team_.win ? lose > team_.lose : win < team_.win;
    }
};

Team team[11];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin >> n && n){
        for(int i = 0; i < n; ++i){
            cin >> team[i].t;

            for(int j = 0; j < n - 1; ++j){
                int a;
                cin >> a;
                if(a == 0) ++team[i].win;
                if(a == 1) ++team[i].lose;
            }
        }

        sort(team, team + n);

        for(int i = n - 1; i >= 0; --i){
            cout << team[i].t << endl;
        }
    }

    return 0;
}