#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		char a[20];
		int b[20][2];
		bool l[20];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			b[i][0] = 0;
			b[i][1] = 0;
			l[i] = false;
			for (int j = 0; j < n - 1; j++) {
				int x;
				cin >> x;
				if (x == 0) b[i][1]++;
				else if (x == 1) b[i][0]++;
			}
		}
		for (int i = 0; i < n; i++) {
			int maxw = 100000, minl = 10000,t=0;
			for (int j = n-1; j >= 0; j--){
				if (!l[j]) {
					if (maxw > b[j][0]) {
						t = j;
						maxw = b[j][0];
					}
					else if (maxw == b[j][0]) {
						if (b[t][1] <= b[j][1]) {
							t = j;
						}
					}
				}
			}
			l[t] = true;
			cout << a[t] << endl;
			maxw = -1;
		}
	}
}