#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

class Team
{
public:
	string name;
	int win,lost,InNo;

	Team(string name = string("str"), int win = 0, int lost = 0, int InNo = 0) :
	name(name),win(win),lost(lost),InNo(InNo){}

	bool operator < (const Team &ano) const
	{
		if(win != ano.win){
			return win > ano.win;
		}
		if(lost != ano.lost){
			return lost < ano.lost;
		}
		if(InNo != ano.InNo){
			return InNo < ano.InNo;
		}
		return name > ano.name;
	}

};

int n;

void solve()
{
	vector<Team> team(n);
	int res;

	for(int i = 0; i < n; i++){
		int win = 0, lost = 0;
		cin >> team[i].name;

		team[i].InNo = i;
		for(int j = 0; j < n-1; j++){
			cin >> res;

			switch(res){
				case 0:
					win++;
				case 1:
					lost++;
			}
		}
		team[i].lost = lost;
		team[i].win = win;
	}

	sort(team.begin(), team.end() );

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

}

int main(void)
{
	while(cin >> n, n){
		solve();
	}
	return 0;
}