#include <iostream>
#include <algorithm>
using namespace std;

struct team {
	char n[2];
	int w = 0, l = 0, t = 0;

	bool operator < (const team & rhs) const {
		return w > rhs.w || (w == rhs.w && l < rhs.l);
	}
};

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		team tm[10];

		for (int i = 0; i < n; i++) {
			cin >> tm[i].n;
			for (int j = 0; j < n - 1; j++) {
				int r;
				cin >> r;

				if (r == 0)
					tm[i].w++;
				else if (r == 1)
					tm[i].l++;
				else if (r == 2)
					tm[i].t++;
			}
		}

		sort(tm, tm + n);

		for (int i = 0; i < n; i++)
			cout << tm[i].n << endl;

		cin >> n;
	}
	
	return 0;
}

