#include<functional>
#include<iostream>
#include<map>
#include<utility>

typedef std::pair<int, int> P;
std::multimap<P, char, std::greater<P>> m;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		m.clear();

		for( int i = 0; i != n; ++i )
		{
			char t;
			std::cin >> t;
			int win = 0, lose = 0;
			for( int j = 0; j != n - 1; ++j )
			{
				int r;
				std::cin >> r;
				if( r != 2 )
					++( r ? lose : win );
			}

			m.insert( std::make_pair( P( win, -lose ), t ) );
		}

		for( auto it = m.begin(); it != m.end(); ++it )
			std::cout << it->second << std::endl;
	}

	return 0;
}