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 <bits/stdc++.h>

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
int M, T, P, R;
struct Team {
  int ACtime[11] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  int WAcnt[11] = {};
  int timecost = 0;
  int ACcnt = 0;
  int id;
  bool operator<(const Team &o) const {
    if (ACcnt == o.ACcnt) {
      if (timecost == o.timecost) {
        return id > o.id;
      } else {
        return timecost < o.timecost;
      }
    } else {
      return ACcnt > o.ACcnt;
    }
  }
};
signed main() {
  while (cin >> M >> T >> P >> R) {
    if (M == 0 && T == 0 && P == 0 && R == 0) break;
    vector<Team> tm(T);
    rep(i, T) tm[i].id = i + 1;
    rep(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;
      if (j == 0) { // AC
        tm[t].ACtime[p] = m;
        tm[t].ACcnt++;
      } else { // WA
        // int tmp = tm[i].WAcnt[p];
        // tmp++;
        // tm[t].WAcnt[p] = tmp;
        tm[t].WAcnt[p]++;
      }
    }
    // rep(i, T) {
    //   rep(j, P) cout << tm[i].WAcnt[j] << ' ';
    //   cout << endl;
    // }

    // score計算
    rep(i, T) rep(j, P) tm[i].timecost += (tm[i].ACtime[j] >= 0 ? tm[i].ACtime[j] + tm[i].WAcnt[j] * 20 : 0);
    sort(all(tm));
    // cout << '\n';
    //
    // cout << "id" << ' ' << "ACcnt" << ' ' << "timecost" << endl;
    // rep(i, T) { cout << tm[i].id << ' ' << tm[i].ACcnt << ' ' << tm[i].timecost << ' ' << endl; }
    // cout << '\n';

    rep(i, T) {
      if (i == 0)
        cout << tm[i].id;
      else {
        if (tm[i - 1].ACcnt == tm[i].ACcnt && tm[i - 1].timecost == tm[i].timecost) {
          cout << "=" << tm[i].id;
        } else
          cout << ',' << tm[i].id;
      }
    }
    cout << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;



int main(){
	int M,T,P,R;
	while(cin >> M >> T >> P >> R && M){
		map<int,map<int,int> > wa;
		map<int,map<int,int> > ac;
		for(int i = 0 ; i < R ; i++){
			int m,t,p,j;
			cin >> m >> t >> p >> j;
			if( j != 0 ){
				wa[t][p]++;
			}else{
				ac[t][p] = m;
			}
		}
		vector< array<int,3> > v;
		for(int i = 1 ; i <= T ; i++){
			array<int,3> sub = {0,0,0};
			sub[2] = -i;
			for(int j = 1 ; j <= P ; j++){
				if( ac[i].count(j) ){
					sub[0]--;
					sub[1] += wa[i][j] * 20 + ac[i][j];
				}
			}
			v.push_back(sub);
		}
		sort(v.begin(),v.end());
		for(int i = 0 ; i < v.size() ; i++){
			if(i){
				if( v[i-1][0] == v[i][0] && v[i][1] == v[i-1][1] ){
					cout << "=";
				}else{
					cout <<",";
				}
			}
			cout << -v[i][2];
		}
		cout << endl;
		
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> S;
int wa[51][11];
int OK[11];
vector<S> v;

//比較関数
bool comp(S lhs, S rhs){
	if(lhs.first != rhs.first){
		return lhs.first < rhs.first;
	}
	if(lhs.second.first != rhs.second.first){
		return lhs.second.first > rhs.second.first;
	}
	if(lhs.second.second != rhs.second.second){
		return lhs.second.second < rhs.second.second;
	}
}

int main(){
while(1){//start
	
	int M, T, P, R;
	cin >> M >> T >> P >> R;
	if(M == 0 and T == 0 and P == 0 and R == 0) break;

	//初期化
	v.resize(T);
	for(int i = 0; i < 51; i++){
		for(int j = 0; j < 11; j++) wa[i][j] = 0;
	}
	for(int i = 0; i < 11; i ++) OK[i] = 0;
	
	
	//データを格納
	for(int i = 0; i < R; i++){
		int m, t, p, j;
		cin >> m >> t >> p >> j;

		if(j == 0){
			v[t - 1].second.first += m + 20*wa[t][p]; 
			OK[t-1] += 1;
		}
		else{
			wa[t][p] += 1;
		}
	}
	
	//vectorにデータを入れる
	for(int i = 1; i <= T; i++){
		//v.push_back(make_pair(OK[i-1], make_pair(sum_m, i)));
		v[i-1].first = OK[i-1];
		v[i-1].second.second = i;
	}
	
	sort(v.begin(), v.end(), comp);
	reverse(v.begin(), v.end());

	cout << 1 << endl;
}//end	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
using namespace std;

struct T{
	int id,solve,pena;
	bool operator<(T a)const{
		if(solve!=a.solve)return solve>a.solve;
		if(pena!=a.pena)return pena<a.pena;
		return id>a.id;
	}
	bool operator==(T a)const{
		return solve==a.solve&&pena==a.pena;
	}
};
int main(){
	int m,t,p,r;
	T team[50];
	while(cin>>m>>t>>p>>r,m|t|p|r){
		for(int i=0;i<t;i++){
			team[i].id=i+1;
			team[i].solve=team[i].pena=0;
		}
		int wrong[50][10]={};
		for(int i=0;i<r;i++){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			if(d==0){
				team[b-1].solve++;
				team[b-1].pena= a+20*wrong[b-1][c-1];
			}else{
				wrong[b-1][c-1]++;
			}
		}
		sort(team,team+t);
		cout<<team[0].id;
		for(int i=1;i<t;i++){
			if(team[i-1]==team[i])cout<<'=';
			else cout<<',';
			cout<<team[i].id;
		}
		cout<<endl;
	}
	return 0;
}