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

struct record
{
    char t;
    int w, l;
};

void sort( record* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w > a[j-1].w )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w == a[j-1].w && a[j].l < a[j-1].l )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}

int main()
{
    int n;
    char d;
    record team[10];

    while( cin >> n )
    {
        if( n == 0 )
            break;

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

            int a = 0, b = 0;
            for( int j = 0; j < n - 1; j++ )
            {
                cin >> d;
                if( d == '0' )
                    a++;
                else if( d == '1' )
                    b++;
                else if( d == '2' );
                else;
            }
            team[i].w = a;
            team[i].l = b;
        }

        sort( team, n );

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

    return 0;
}

