// 2011/02/06 Tazoe

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

class Team{
	public:
		char name;
		int  win;
		int  defeat;
		int  draw;

		bool operator < (const Team& t) const
		{
			if(win==t.win)
				return defeat<t.defeat;
			else
				return win>t.win;
		}
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		Team T[10];
		for(int i=0; i<n; i++){
			cin >> T[i].name;
			T[i].win = T[i].defeat = T[i].draw = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					T[i].win++;
				else if(r==1)
					T[i].defeat++;
				else if(r==2)
					T[i].draw++;
			}
		}

		stable_sort(T, T+n);

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

	return 0;
}