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;

int main() {
  for(int M, T, P, R; cin >> M >> T >> P >> R && (M|T|P|R);) {
    vector<int> ac(T, 0), ti(T, 0);
    for(int i = 0; i < R; ++i) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if(!j) {
        ++ac[t-1];
        ti[t-1] += m;
      }
    }
    vector<vector<int> > v;
    for(int i = 0; i < T; ++i) {
      vector<int> u(3);
      u[0] = ac[i];
      u[1] = -ti[i];
      u[2] = i+1;
      v.push_back(u);
    }
    sort(v.begin(), v.end(), greater<vector<int> >());
    for(int i = 0; i < v.size(); ++i) {
      if(i) {
        cout << (v[i-1][0] == v[i][0] && v[i-1][1] == v[i][1] ? '=' : ',');
      }
      cout << v[i][2];
    }
    cout << endl;
  }
  return 0;
}

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

int M, T, P, R;

struct Team{
	int id, ac, timecost;
	int wa[11];
	Team(int i){
		id = i;
		ac = 0; timecost = 0;
		for(int i = 0; i < 11; i++) wa[i] = 0;
	}
};

bool compare(const Team &a, const Team &b){
	if(a.ac != b.ac) return a.ac > b.ac;
	else if(a.timecost != b.timecost) return a.timecost < b.timecost;
	else return a.id > b.id;
}

int main(){
	while(cin >> M >> T >> P >> R && M != 0 && T != 0 && P != 0 && R != 0){
		vector<Team> teams;
		for(int i = 0; i < T; i++){
			Team t(i);
			teams.push_back(t);
		}

		for(int i = 0; i < R; i++){
			int m, t, p, j;
			cin >> m >> t >> p >>j;
			if(j == 0){
				teams[t-1].ac++;
				teams[t-1].timecost += m + teams[t-1].wa[p] * 20;
			}else{
				teams[t-1].wa[p]++;
			}
		}

		sort(teams.begin(), teams.end(), compare);

		int p_ac = -1, p_tc = -1;
		for(int i = 0; i < T; i++){
			if (i>0) {
				if(teams[i-1].ac== teams[i].ac && teams[i-1].timecost == teams[i].timecost) cout << "=";
				else cout << ",";	
			}
			cout << teams[i].id+1;
			/*
			if(p_ac == teams[i].ac && p_tc == teams[i].timecost){
				cout << "=" << teams[i].id + 1;
			}else if(i != 0){
				cout << "," << teams[i].id + 1;
				p_ac = teams[i].ac;
				p_tc = teams[i].timecost;
			}else{
				cout << teams[i].id + 1;
				p_ac = teams[i].ac;
				p_tc = teams[i].timecost;
			}*/
		}
		cout << endl;
	}
	return 0;
}

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

struct agg{
  int sol,tim,num;
  int wrg[11];
};

class ctr{
public:
  bool operator()(const agg& left,const agg& right)const{
    if(left.sol == right.sol && left.tim == right.tim){
      return left.num > right.num;
    }
    else if(left.sol == right.sol) return left.tim < right.tim;
    else return left.sol > right.sol; 
  }
};

void init(int n,vector<agg> *trg){
  for(int i=1;i<n+1;i++){
    (*trg)[i].sol = 0;
    (*trg)[i].tim = 0;
    (*trg)[i].num = i;
    memset((*trg)[i].wrg,0,sizeof((*trg)[i].wrg));
  }
}

int main(){
  int M,T,P,R;
  while(cin >> M >> T >> P >> R,M||T||P||R){
    vector<agg>info(T+1);
    init(T,&info);

    while(R--){
      int m,t,p,j;
      cin >> m >> t >> p >> j;
      if(j == 0){
	info[t].tim += info[t].wrg[p] * 20 + m;
	info[t].sol++;
      }
      else info[t].wrg[p]++;
    }

    sort(info.begin()+1,info.end(),ctr());
    for(int i=1;i<T;i++){
      cout << info[i].num;
      cout << (info[i].sol == info[i+1].sol && info[i+1].tim == info[i].tim ? '=' : ',');
    }
    cout << info[T].num <<  endl;
  }
}

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

using namespace std;

struct team {
	int id, ac, pena;
	int wa[16];
	team(int id, int prob) : id(id), ac(0), pena(0){
		for (int i = 0; i < 16; i++){
			wa[i] = 0;
		}
	}

	void correct(int time, int prob){
		ac++;
		pena += (time + (20 * wa[prob]));
	}
	void uncorrect(int prob){
		wa[prob]++;
	}

	bool operator<(const team& a) const
	{
		if (ac == a.ac){
			if (pena == a.pena) return id > a.id;
			else return pena < a.pena;
		}
		else return ac > a.ac;
	}
	bool operator==(const team& a) const
	{
		return (ac == a.ac) && (pena == a.pena);
	}
};

int main(void)
{
	int M, T, P, R;

	while (cin >> M >> T >> P >> R, T){
		// wa[team][problem];
		int m, t, p, j;
		vector <team> data;
		for (int i = 0; i < T; i++){
			data.push_back(team(i + 1, P));
		}

		for (int i = 0; i < R; i++){
			cin >> m >> t >> p >> j;
			if (j != 0) {
				data[t - 1].uncorrect(p);
			}
			else {
				data[t - 1].correct(m, p);
			}
		}
		sort(data.begin(), data.end());

		for (int i = 0; i < T; i++){
			if (i == 0) {
				cout << data[i].id;
				continue;
			}
			if (data[i - 1] == data[i]) cout << "=";
			else cout << ",";
			cout << data[i].id;
		}
		cout << endl;
	}
	return 0;
}