#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<char, int[3]> p, pair<char, int[3]> q) 
{
    return (p.second[0] > q.second[0]) || (p.second[0] == q.second[0] && p.second[1] < q.second[1]);
}


int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;
        
        pair<char, int[3]> team[10];

        for (int i = 0; i < n; i++) {
            char ch;
            
            cin >> team[i].first;
            for (int j = 0; j < n - 1; j++) {
                int ind;
                cin >> ind;
                team[i].second[ind]++;
            }
        }
        
        stable_sort(team, team + n, cmp);

        for (int i = 0; i < n; i++)
            cout << team[i].first << endl;
    }

    return 0;
}