#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

struct team
{
	string id;
	int win;
	int lose;

	team(string s,int w,int l) : id(s),win(w),lose(l) {}

	bool operator < (const team& t) const{
		return win == t.win ? lose < t.lose : win > t.win;
	}
};

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<team> v;

		rep(i,n)
		{
			string s;
			cin >> s;
			
			int w = 0;
			int l = 0;
			
			rep(j,n-1)
			{
				int temp;
				cin >> temp;

				if(temp == 0) w++;
				else if(temp == 1) l++;
			}

			v.push_back(team(s,w,l));
		}

		sort(v.begin(),v.end());


		rep(i,v.size())
		{
			cout << v[i].id <<  endl;
		}
	}
	return 0;
}