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

struct play{
	char team;
	int win;
	int lose;
};

bool cmp(play lhs, play rhs)
{
	if (lhs.win == rhs.win){
		return (lhs.lose < rhs.lose);
	}
	
	return (lhs.win > rhs.win);
	
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector<play> a(n, (play){' ', 0, 0});
		
		for (int i = 0; i < n; i++){
			cin >> a[i].team;
			for (int j = 0; j < n - 1; j++){
				int num;
				cin >> num;
				a[i].win += num == 0 ? 1 : 0;
				a[i].lose += num == 1 ? 1 : 0;
			}
		}
		
		sort(a.begin(), a.end(), cmp);
		
		for (int i = 0; i < n; i++){
			cout << a[i].team << endl;
		}
	}
	
	return (0);
}