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

int main()
{
	while (1) 
	{
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, string>s;
		for (int p = 0; p < a; p++) {
			string b;
			cin>>b;
			int c = 0;
			for (int d = 0; d <(a-1); d++) {
				int e;
				cin >> e;
				if (e == 0)c -= 100;
				else if (e == 2)c--;
			}
			s.insert(pair<double, string>(c+p/(double)100, b));
		}
		for (auto q = s.begin(); q != s.end(); q++) {
			cout << q->second << endl;
		}
	}
}