Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw int
}
type lessFunc func(p1, p2 *Team) bool
type multiSorter struct {
	teams []Team
	less    []lessFunc
}
func (ms *multiSorter) Sort(teams []Team) {
	ms.teams = teams
	sort.Sort(ms)
}
func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.teams)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.teams[i], ms.teams[j] = ms.teams[j], ms.teams[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.teams[i], &ms.teams[j]
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	win := func(c1, c2 *Team) bool {
		return c1.Win > c2.Win
	}
	lose := func(c1, c2 *Team) bool {
		return c1.Lose < c2.Lose
	}
	draw := func(c1, c2 *Team) bool {
		return c1.Draw < c2.Draw
	}

	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			name := buf[0]
			tmp := make([]int, n-1)
			for i := range tmp {
				tmp[i], _ = strconv.Atoi(buf[i+1])
			}
			cntwin, cntlose, cntdraw := 0, 0, 0
			for _, v := range tmp {
				switch v {
				case 1:
					cntlose++
				case 0:
					cntwin++
				case 2:
					cntdraw++
				}
			}
			teams[i] = Team{name, cntwin, cntlose, cntdraw}
		}
		OrderedBy(win, lose).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: // #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
int INPUT_INT() {int d;cin>>d;return d;} // 入力をpush_back(d)やarray[d]に使う時に無駄な変数を使わない

// ------------------- include, typedef, define END. -------------------

void solveAndOutput(MuMAPIC &result){
	foreach_it(MuMAPIC, it, result){
		cout << (*it).second << endl;
	}
}

int main(){
	/* 方針
	 * A:381 , B:370 , C:40 , ...
	 * 百の位は勝ち数, 十の位は(9-負け数), 一の位は引き分け数.
	 * 入力チーム数が10以下（= 繰り上がり繰り下がりがないこと）を前提としている.
	 *
	 * また, 勝ち, 負け以外に引き分けしかない(無効試合とかない)ことを前提に, 引き分け数も計算に入れた.
	 */
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1167731
	// このコードは、↑のコードを、ビット演算使用してみたversionに書き換えたものである.

	int n = 0;
	char in_char;
	while (cin >> n, n){
		MuMAPIC result;

		// 各team入力
		FOR(teamSum, 0, n){
			// seisekiCount[0] = win, [1]=lose, [2]=hikiwake
			VI seisekiCount(3, 0);
			int temp_mapin = 0;

			cin >> in_char;
			FOR(i, 0, n - 1)
				seisekiCount[INPUT_INT()]++;

			//temp_mapin = seisekiCount[0] * 100 + (9 - seisekiCount[1]) * 10 + seisekiCount[2];
			FOR(i, 0, seisekiCount.size()){
				if (i == 1)
					temp_mapin += 9 - seisekiCount[i];
				else
					temp_mapin += seisekiCount[i];
				// 最大で+9される.つまり+1001される.よってずらす分は4bit以上.
				temp_mapin <<= 4;
			}
			result.insert(MP(temp_mapin, in_char));
		}
		// all teams input END.
		solveAndOutput(result);
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>

using namespace std;

int main(void){
	int a,b,n;
	char t[10];
	int w[10],l[10];
	while(1){
		memset(w,0,sizeof(w));
		memset(l,0,sizeof(l));
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> t[a];
			for(b=0;b<n-1;b++){
				int b;
				cin >> b;
				if(b==0)w[a]++;
				if(b==1)l[a]++;
			}
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				if(w[b]>w[a] || w[b]==w[a] && l[b]<l[a])swap(t[a],t[b]),swap(w[a],w[b]),swap(l[a],l[b]);
			}
		}
		for(a=0;a<n;a++){
			cout << t[a] << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
long long int i,j,k,n,sum[9],data,a,b;
int main(void)
{
	char name[10];
	while(1) {
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) sum[i]=0;
		
		for(i=0;i<n;i++) {
			cin>>name[i];
			a=b=0;
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) a++;
				else if(data==1) b++;
			}
			sum[i]=a*100000000+b*-1;
		}
		for(i=0;i<n;i++) {
			for(j=i;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[9];
	int data;
	char name[10];
	while(1) {
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) sum[i]=0;
		
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=10000;
				else if(data==1) sum[i]-=1;
			}
		}
		
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>

using namespace std;

int main(void){
	int a,b,n;
	char t[20];
	int w[10],l[10];
	while(1){
		memset(t,0,sizeof(w));
		memset(w,0,sizeof(w));
		memset(l,0,sizeof(l));
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> t[a];
			for(b=0;b<n-1;b++){
				int b;
				cin >> b;
				if(b==0)w[a]++;
				if(b==1)l[a]++;
			}
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				if(w[b]>w[a] || w[b]==w[a] && l[b]<l[a])swap(t[a],t[b]),swap(w[a],w[b]),swap(l[a],l[b]);
			}
		}
		for(a=0;a<n;a++){
			cout << t[a] << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<char> t(n);
    vector<int> win(n, 0), lose(n, 0), ord(n);
    iota(ord.begin(), ord.end(), 0);
    for (int i = 0; i < n; i++) {
      cin >> t[i];
      for (int j = 0; j < n - 1; j++) {
        int r;
        cin >> r;
        if (r == 0) win[i]++;
        else if (r == 1) lose[i]++;
      }
    }
    sort(ord.begin(), ord.end(), [&](int a, int b) {
      if (win[a] != win[b]) return win[a] > win[b];
      return lose[a] < lose[b];
    });
    for (int i = 0; i < n; i++) {
      cout << t[ord[i]] << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>

using namespace std;

priority_queue<pair<pair<pair<int, int>,int>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		int win, lose;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0;lose = 0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}results.emplace(make_pair(make_pair(make_pair(win,-lose),i),name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}