#include<iostream>

using namespace std;

struct sct
{
	char t;
	int r1[11];
	int win;
	int lose;
	int drow;
	int input;
};

int main()
{
	while(true)
	{
		int n = 0;
		sct team[11];
		sct cl = {0, 0, 0, 0, 0, 0}; 

		cin >> n;

		if(n == 0)
		{
			return false;
		}

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

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

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n - 1; j++)
			{
				if(team[i].r1[j] == 0)
				{
					team[i].win++;	
				}
				
				else if(team[i].r1[j] == 1)
				{
					team[i].lose++;
				}
				else if (team[i].r1[j] == 2)
				{
					team[i].drow++;
				}				
			}
		}

		for(int i = 0; i < n; i++)
		{
			for(int j = i; j < n; j++)
			{
				if(team[i].win < team[j].win)
				{
					sct tmp = team[i];
					team[i] = team[j];
					team[j] = tmp;
				}
				else if(team[i].win == team[j].win)
				{
					if(team[i].lose > team[j].lose)
					{
						sct tmp = team[i];
						team[i] = team[j];
						team[j] = tmp;
					}
					else if(team[i].lose == team[j].lose)
					{
						if(team[i].input > team[j].input)
						{
							sct tmp = team[i];
							team[i] = team[j];
							team[j] = tmp;
						} 	
					}
				}
			}
		}

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