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

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

bool comp(team a, team b) {
    if (a.win > b.win) return true;
    else if (a.win < b.win) return false;
    return a.lose - b.lose;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        
        team t[n];
        for (int i = 0; i < n; i++) {
            t[i].win = 0;
            t[i].lose = 0;
        }

        for (int i = 0; i < n; i++) {
            cin >> t[i].name;
            for (int j = 0; j < n - 1; j++) {
                int r;
                cin >> r;
                if (r == 0) t[i].win++;
                else if (r == 1) t[i].lose++;
            }
        }
        sort(t, t + n, comp);
        for (int i = 0; i < n; i++) {
            cout << t[i].name << endl;
        }
    }
}