Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		M, T, P, R := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		if M == 0 {
			break
		}
		score := make([]struct{ num, time, index int }, T)
		submit := make([][]int, T)
		for i := 0; i < T; i++ {
			score[i].index = i + 1
			submit[i] = make([]int, P)
		}

		for i := 0; i < R; i++ {
			m, t, p, j := io.NextInt(), io.NextInt()-1, io.NextInt()-1, io.NextInt()
			if j == 0 {
				score[t].num++
				score[t].time += submit[t][p]*20 + m
			} else {
				submit[t][p]++
			}
		}
		sort.SliceStable(score, func(i, j int) bool {
			return score[i].num < score[j].num || score[i].num == score[j].num && score[i].time > score[j].time
		})

		for i := T - 1; i > 0; i-- {
			io.Printf("%d", score[i].index)
			if score[i].num == score[i-1].num && score[i].time == score[i-1].time {
				io.Printf("=")
			} else {
				io.Printf(",")
			}
		}
		io.Println(score[0].index)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		ll M, T, P, R;
		cin>>M>>T>>P>>R;
		if(M == 0 && T == 0 && P == 0 && R == 0) break;
		vector<vector<ll> > wa(T, vector<ll>(P, 0));
		vector<vector<ll> > tm(T, vector<ll>(P, -1));
		REP(i, R) {
			ll m, t, p, j;
			cin>>m>>t>>p>>j;
			--t;
			--p;
			if(j == 0) {
				tm[t][p] = m;
			} else {
				++wa[t][p];
			}
		}
		vector<pair<pair<ll, ll>, ll> > ans(T, pair<pair<ll, ll>, ll>(pair<ll, ll>(0, 0), 0));
		REP(i, T) {
			ans[i].second = i + 1;
		}
		REP(i, T) {
			REP(j, P) {
				if(tm[i][j] != -1) {
					++ans[i].first.first;
					ans[i].first.second -= tm[i][j];
					ans[i].first.second -= wa[i][j] * 20;
				}
			}
		}
		sort(ALL(ans), greater<pair<pair<ll, ll>, ll> >());
		REP(i, T) {
			cout<<ans[i].second;
			if(i + 1 < T && ans[i].first == ans[i + 1].first) {
				cout<<'=';
			} else if(i + 1 < T) {
				cout<<',';
			}
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct T{
  T(){ac=0;t=0;}
  int n,ac,t;
  vector<int> p;
};
bool operator<(T a,T b){
  if(a.ac!=b.ac){
    return a.ac>b.ac;
  }else if(a.t!=b.t){
    return a.t<b.t;
  }else{
    return a.n>b.n;
  }
}
bool operator==(T a,T b){
  return a.ac==b.ac && a.t==b.t;
}

vector<T> team;
int M,T,P,R;


bool input(){
  cin>>M>>T>>P>>R;
  if(M==0&&T==0&&P==0&&R==0)return false;
  team.clear();team.resize(T);
  for(int i=0;i<T;i++){
    team[i].n=i+1;
    team[i].p.resize(P+1);
  }
  return true;
}

void que(){
  for(int i=0;i<R;i++){
    int m,t,p,j;
    cin>>m>>t>>p>>j;
    t--;p--;
    if(j==0){
      team[t].t += team[t].p[p] + m;
      team[t].ac++;
    }else{
      team[t].p[p]+=20;
    }
  }
}

void solve(){
  sort(team.begin(),team.end());
}

void print(){
  for(int i=0;i<team.size()-1;i++){
    cout<<team[i].n;
    if(team[i]==team[i+1]){
      cout<<"=";
    }else{
      cout<<",";
    }
  }
  cout<<team[team.size()-1].n<<endl;
}

int main(){
  while(input()){
    que();
    solve();
    print();
  }
}

C++: #include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

struct teaminfo {
  int id;
  int ac;
  int time;
  int wan[ 11 ];
  bool operator<( const teaminfo &t ) const;
  bool operator==( const teaminfo &t ) const;
};

bool teaminfo::operator<( const teaminfo &t ) const {
  if( this->ac == t.ac ) {
    if( this->time == t.time ) {
      return this->id < t.id;
    }
    return this->time > t.time;
  }
  return this->ac < t.ac;
}

bool teaminfo::operator==( const teaminfo &t ) const {
  return this->time == t.time && this->ac == t.ac;
}


int main() {
  while( 1 ) {
    int m, t, p, r;
    teaminfo ti[ 51 ];
    cin >> m >> t >> p >> r;
    if( !m && !t && !p && !r ) { break; }
    for( int i = 1; i <= t; i++ ) {
      ti[ i ].id = i;
      ti[ i ].ac = 0;
      ti[ i ].time = 0;
      for( int j = 1; j <= p; j++ ) {
        ti[ i ].wan[ j ] = 0;
      }
    }
    for( int i = 0; i < r; i++ ) {
      int mk, tk, pk, jk;
      cin >> mk >> tk >> pk >> jk;
      if( jk == 0 ) { // ac
        ti[ tk ].ac++;
        ti[ tk ].time += ( mk + ti[ tk ].wan[ pk ] * 20 );
      } else { // wa
        ti[ tk ].wan[ pk ]++;
      }

    }
    sort( ti + 1, ti + t + 1 );
    for( int i = t; i > 0; i-- ) {
      cout << ti[ i ].id << flush;
      if( i != 1 ) {
        if( ti[ i - 1 ] == ti[ i ] ) {
          cout << "=" << flush;
        } else {
          cout << "," << flush;
        }
      }
    }
    cout << endl;
  }

  return EXIT_SUCCESS;
}