#include <iostream>
#include <algorithm>

using namespace std;

struct Team
{
	char name[2];
	int win;
	int lose;
};

class team_comparator
{
public:
	bool operator() (Team t1, Team t2)
	{
		if(t1.win != t2.win) return t1.win > t2.win;
		else return t1.lose < t2.lose;
	}
};

Team S[10];

int main(int argc, char** argv)
{
	int n, r;
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> S[i].name;
			S[i].win = 0;
			S[i].lose = 0;
			for(int j=0; j<n-1; j++)
			{
				cin >> r;
				switch(r)
				{
					case 0:
						S[i].win++;
						break;
					case 1:
						S[i].lose++;
						break;
				}
			}
		}

		sort(&S[0], &S[n], team_comparator());

		for(int i=0; i<n; i++)
		{
			cout << S[i].name << endl;
		}
	}

	return 0;
}