// 2011/02/06 Tazoe

#include <iostream>
using namespace std;

struct team{
	char t;
	int win;
	int los;
	int drw;
	int ord;
};

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

		struct team tea[10];
		for(int i=0; i<n; i++){
			tea[i].win = 0;
			tea[i].los = 0;
			tea[i].drw = 0;
			tea[i].ord = i;

			cin >> tea[i].t;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					tea[i].win++;
				else if(r==1)
					tea[i].los++;
				else if(r==2)
					tea[i].drw++;
			}
		}

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(tea[i].win<tea[j].win||(tea[i].win==tea[j].win&&tea[i].los>tea[j].los)
				 ||(tea[i].win==tea[j].win&&tea[i].los==tea[j].los&&tea[i].ord>tea[j].ord)){
					struct team tmp = tea[i];
					tea[i] = tea[j];
					tea[j] = tmp;
				}

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

	return 0;
}