#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;
typedef pair<string, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec;
		set<int> Set;
		for(int i = 0; i < n; ++i)
		{
			string t;
			cin >> t;
			int sum = 0;
			for(int j = 0; j < n - 1; ++j)
			{
				int a;
				cin >> a;
				if(a == 0)
				{
					sum += 10000;
				}
				else if(a == 2)
				{
					sum += 100;
				}
			}
			Vec.push_back(P(t, sum));
			Set.insert(sum);
		}
		set<int>::reverse_iterator rit = Set.rbegin();
		while(rit != Set.rend())
		{
			for(int i = 0; i < n; ++i)
			{
				if(*rit == Vec[i].second)
				{
					cout << Vec[i].first << endl;
				}
			}
			++rit;
		}
	}
}

int main()
{
	solve();
	return(0);
}