#include <iostream>
using namespace std;

struct Team {
    char name;
    int win, lose;
};

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        Team* team = new Team [n];
        for (int i = 0; i < n; i++) {
            cin >> team[i].name;
            for (int j = 0; j < n - 1; j++) {
                int score;
                cin >> score;
                if (score == 0) {
                    team[i].win++;
                } else if (score == 1) {
                    team[i].lose++;
                }
            }
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - 1 - i; j++) {
                if (team[j].win < team[j + 1].win
                    || (team[j].win == team[j + 1].win && team[j].lose > team[j + 1].lose)) {
                    Team temp = team[j];
                    team[j] = team[j + 1];
                    team[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            cout << team[i].name << endl;
        }
    }
}