#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, char> scores[10];
		for (int i = 0; i < n; ++i)
		{
			char name;
			scanf(" %c", &name);
			int w, l;
			w = l = 0;
			for (int j = 1; j < n; ++j)
			{
				int t;
				scanf("%d", &t);
				if (t == 0)
					++w;
				else if (t == 1)
					++l;
			}
			scores[i] = make_pair(w*1000 - l, name);
		}
		sort(scores, scores+n, greater<pair<int, char> >());
		for (int i = 0; i < n; ++i)
			printf("%c\n", scores[i].second);
	}

	return 0;
}