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>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define reps(i, n, m) for (int i = (int) n; i < (int) m; i++)

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

bool init() {
	cin >> M >> T >> P >> R;
	v.clear();
	v.resize(T, vector<int>(P, 0));
	return M != 0;
}

bool check(int a, int b, int c, int d) {
	int A = a * a + b * b;
	int B = c * c + d * d;
	if (A != B) return A < B;
	return a < c;
}

struct score {
	int x;
	int s;
	int t;
};

void solve() {
	vector<score> S(T);
	rep(i, T) S[i].x = i+1;
	rep(i, R) {
		int m, t, p, j;
		cin >> m >> t >> p >> j;
		if (j) {
			v[t-1][p-1] += 20;
		} else { // AC
			S[t-1].s++;
			S[t-1].t += m + v[t-1][p-1];
		}
	}
	sort(S.rbegin(), S.rend(), [](auto a, auto b) {
		return a.s == b.s ? 
				a.t == b.t ? a.x < b.x :
				a.t > b.t : a.s < b.s;
	});
	cout << S[0].x;
	reps(i, 1, T) {
		if (S[i-1].s == S[i].s && S[i-1].t == S[i].t) cout << "=";
		else cout << ",";
		cout << S[i].x;
	}
	cout << endl;
}

int main() {
	while (init()) {
		solve();
	}
}

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

int main(){
	while(true){
		int M, T, P, R;
 		cin >> M >> T >> P >> R;
	
		if(M==0 && T==0 && P==0 && R==0)
			break;
		
		int CP[50], TT[50], PT[50][10];
		for(int i=0;	i<T; i++){
			CP[i] = TT[i] = 0;
			for(int j=0; j<P; j++)
				PT[i][j] = 0;
		}

		for(int i=0; i<R; i++){
			int m, t, p, r;
			cin >> m >> t >> p >> r;
			
			if(j==0){
				CP[t-1]++;
				TT[t-1] += (m+PT[t-1[p-1]);
			}
			else{
				PT[t-1][p-1] += 20;
			}
		}
	
		int tnow, tpre = -1;
		bool flg[50];
			flg[i] = false;
				
		for(int i=0; i<T; i++){
			tnow = -1;
			for(int j=0; j<T; j++){
				if(flg[j])
					continue;
				if(tnow==-1){
					tnow = j;
				}
				else{
					if(CP[j]>CP[tnow] || (CP[j]==CP[tnow] && TT[j]==TT[tnow])){
					}
				}
			}
			
			if(tpre!=-1){
				if(CP[tnow]==CP[tpre] && tt[tnow]==TT[tpre])
					cout << '=';
				else
					cout << ',';
				}
				cout << tnow+1;
				
				flg [tnow] = true;
				tpre = tnow;

			}
		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0){
      break;
    }
    vector<vector<int>> s(T, vector<int>(P, -1));
    vector<vector<int>> wa(T, vector<int>(P, 0));
    for (int i = 0; i < R; i++){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;
      if (j == 0){
        if (s[t][p] == -1){
          s[t][p] = m + wa[t][p] * 20;
        }
      } else {
        wa[t][p]++;
      }
    }
    vector<tuple<int, int, int>> score(T);
    for (int i = 0; i < T; i++){
      int ac = 0;
      int time = 0;
      for (int j = 0; j < P; j++){
        if (s[i][j] != -1){
          ac++;
          time += s[i][j];
        }
      }
      score[i] = make_tuple(ac, - time, i + 1);
    }
    sort(score.rbegin(), score.rend());
    for (int i = 0; i < T; i++){
      cout << get<2>(score[i]);
      if (i < T - 1){
        if (get<0>(score[i]) == get<0>(score[i + 1]) && get<1>(score[i]) == get<1>(score[i + 1])){
          cout << '=';
        } else {
          cout << ',';
        }
      }
    }
    cout << endl;
  }
}

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

using namespace std;

struct data_t {
	int ID;
	int time;
	int ac;

	bool operator<(const data_t& right) const {
		if (ac == right.ac) {
			if (time == right.time) {
				return (ID > right.ID);
			}
			else {
				return (time < right.time);
			}
		}
		else {
			return (ac > right.ac);
		}
	}
};

int main(void) {
	int M,T,P,R;
	while (cin >> M >> T >> P >> R, M) {
		vector<data_t> data(T);
		for (int i = 0; i < T; ++i) {
			data[i].ID = i+1;
			data[i].time = 0;
			data[i].ac = 0;
		}

		int m,t,p,judge;
		vector< vector<int> > wrong(T,vector<int>(P,0));
		for (int i = 0; i < R; ++i) {
			cin >> m >> t >> p >> judge;
			if (judge != 0) {
				++wrong[t-1][p-1];
			}
			else {
				++data[t-1].ac;
				data[t-1].time += m + (20 * wrong[t-1][p-1]);
			}
		}
		sort(data.begin(),data.end());
		for (int i = 0; i < T; ++i) {
			cout << data[i].ID;
			if (i < T-1) {
				if (data[i].ac == data[i+1].ac && data[i].time == data[i+1].time) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		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||T||P||R){
	
		//??£?????°,????????????????¨?,???????????????
		vector<pair<pair<int,int>,int>> v(T,make_pair(make_pair(0,0),0));
		for(int i=0;i<T;i++){
			v[i].second = i+1;
		}
		vector<vector<int>> unsolved(T,vector<int>(P,0));
		for(int i=0;i<R;i++){
			int m,t,p,j;
			cin >> m >> t >> p >> j;
			if(j){
				unsolved[t-1][p-1]++;
				continue;
			}
			v[t-1].first.first++;
			v[t-1].first.second-=m;
			v[t-1].first.second-=unsolved[t-1][p-1]*20;
		}
		sort(v.begin(),v.end(),greater<pair<pair<int,int>,int>>());
		cout << v[0].second;
		for(int unsigned i = 0;i<v.size()-1;i++){
			if(v[i].first.first == v[i+1].first.first && v[i].first.second == v[i+1].first.second){
				cout << "=";
			} else {
				cout << ",";
			}
			cout << v[i+1].second;
		}
		cout << endl;
	}	
	return 0;
}