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

int main() {
    int n;
    while (cin >> n, n) {
        vector<pair<pair<int,int>, pair<int,char> > > res;
        for (int i=0; i<n; ++i) {
            char t;
            cin >> t;
            int r, win = 0, lose = 0;
            for (int j=0; j<n-1; ++j) {
                cin >> r;
                if (r == 0) ++ win;
                else if (r == 1) ++ lose;
            }
            res.push_back(make_pair(make_pair(-win, lose), make_pair(i, t)));
        }
        sort(res.begin(), res.end());
        for (int i=0; i<(int)res.size(); ++i) {
            cout << res[i].second.second << endl;
        }
    }
    return 0;
}