#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int w[15],l[15];
int a[15];
bool cmp(const int &a,const int &b)
{
	if(w[a] != w[b]) return w[a] > w[b];
	if(l[a] != l[b]) return l[a] < l[b];
	return a < b;
}
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n == 0) return 0;
		char h[15];
		fill(w,w+15,0);
		fill(l,l+15,0);
		for(int i=0;i<15;i++) a[i] = i;
		for(int i=0;i<n;i++)
		{
			scanf(" %c",&h[i]);
			for(int j=1;j<n;j++)
			{
				int x; cin >> x;
				if(x == 0) w[i]++;
				else if(x == 1) l[i]++;
			}
		}
		sort(a,a+n,cmp);
		for(int i=0;i<n;i++) cout << h[a[i]] << endl;
	}
}