#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vs names(n);
		vvi table(n,vi(n));
		rep(i,n){
			cin>>names[i];
			rep(j,n){
				if(i==j)
					continue;
				cin>>table[i][j];
			}
		}
		vi scores(n);
		rep(i,n) rep(j,n){
			if(i==j)
				continue;
			if(table[i][j]==0)
				scores[i]+=100;
			else if(table[i][j]==1)
				scores[i]-=1;
		}
		rep(i,n)
			for(int j=i;j>0;j--)
			if(scores[j-1]<scores[j]){
				swap(names[j-1],names[j]);
				swap(scores[j-1],scores[j]);
			}
		rep(i,n)
			cout<<names[i]<<endl;
	}
	
	return 0;
}