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<cstring>
#include<queue>
using namespace std;

struct team{
  int id;
  int ans;
  int time;
  team(int i,int a,int t): id(i),ans(a),time(t){}

  bool operator >(const team &e)const {
    if(ans!=e.ans)
      return ans > e.ans;
    if(time != e.time)
      return time<e.time;
    return id>e.id;
  }
  bool operator <(const team &e)const {
    if(ans!=e.ans)
      return ans < e.ans;
    if(time != e.time)
      return time>e.time;
    return id<e.id;
  }
};

int main()
{
  int m,t,p,r;
  for(;cin>>m>>t>>p>>r,m;)
    {
      int teamans[t+1];
      int teamtime[t+1];
      int teampena[t+1][p+1];
      memset(teamans,0,sizeof(teamans));
      memset(teamtime,0,sizeof(teamtime));
      memset(teampena,0,sizeof(teampena));
      for(int i=0;i<r;i++)
	{
	  int mm,tt,pp,jj;
	  cin>>mm>>tt>>pp>>jj;
	  //  if(m>mm)
	  //   continue;
	  if(jj==0)
	    {
	      teamans[tt]++;
	      teamtime[tt]+=mm+teampena[tt][pp];
	    }
	  else
	    {
	      teampena[tt][pp]+=20;
	    }
	}
      priority_queue<team> qu;
      for(int i=1;i<=t;i++)
	{
	  qu.push(team(i,teamans[i],teamtime[i]));
	}
      int buf,buf2;
      bool flag=false;
      
      while(!qu.empty())
	{
	  team tmp =qu.top();
	  qu.pop();
	  if(flag)
	    {
	      if(tmp.ans==buf &&tmp.time==buf2)
		cout<<"=";
	      else
		cout<<",";
	    }
	  flag=true;
	  buf=tmp.ans;
	  buf2=tmp.time;
	  cout<<tmp.id;
	}
      cout<<endl;
      
    }


}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int m,t,p,r;
	while(cin>>m>>t>>p>>r){
		if(m==0) break;
		int mm,tt,pp,j;
		int ac[t+1],wa[t+1][p+1],pen[t+1];
		for(int i=0;i<=t;i++){
			ac[i]=0;
			pen[i]=0;
			for(int j=0;j<=p;j++){
				wa[i][j]=0;
			}
		}
		for(int i=0;i<r;i++){
			cin>>mm>>tt>>pp>>j;
			if(j!=0){
				wa[tt][pp]++;
			}
			else{
				ac[tt]++;
				pen[tt]=pen[tt]+wa[tt][pp]*20+mm;
				wa[tt][pp]=0;
			}
		}
		int ctct=0;
		for(int i=1;i<=t;i++){
			int acmax=-1,penmin;
			for(int j=t;j>=1;j--){
				if(ac[j]>acmax){
					acmax=ac[j];
					penmin=pen[j];
				}
				else if(ac[j]==acmax){
					penmin=min(penmin,pen[j]);
				}
			}
			int ct=0;
			if(acmax==-1) break;
			else if(ctct>0) cout<<",";
			ctct++;
			for(int j=t;j>=1;j--){
				if(acmax==ac[j]&&penmin==pen[j]){
					if(ct>0) cout<<"=";
					cout<<j;
					ac[j]=-2;
					pen[j]=0;
					ct++;
				}
			}
		}
		cout<<endl;
	}
    return 0;
}

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

struct team{
    int cor,pen,id;
    vector<int>AC;
    vector<int>correct;
    vector<int>penalty;
};
bool com(team t1,team t2){
    return t1.cor==t2.cor?t1.pen==t2.pen?t1.id>t2.id:t1.pen<t2.pen:t1.cor>t2.cor;
}
bool com2(team t1,team t2){
    return t1.cor==t2.cor?t1.pen<t2.pen:t1.cor>t2.cor;
}
int main(){
    int M,T,P,R,m,t,p,j;
    while(cin>>M>>T>>P>>R,M){
        vector<team>vec(T);
        for(int i=0;i<T;i++){
            vec[i].id=i;
            vec[i].correct.resize(P,0);
            vec[i].penalty.resize(P,0);
            vec[i].AC.resize(P,0);
            vec[i].cor=0;
            vec[i].pen=0;
        }
        for(int i=0;i<R;i++){
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0){
                vec[t].correct[p]=vec[t].penalty[p]+m;
                vec[t].AC[p]=1;
            }
            else{
                vec[t].penalty[p]+=20;
            }
        }
        for(int i=0;i<T;i++){
            for(int a=0;a<P;a++){
                if(vec[i].AC[a]>0){
                    vec[i].cor++;
                    vec[i].pen+=vec[i].correct[a];
                }
            }
        }
        sort(vec.begin(),vec.end(),com);
        
        for(int i=0;i<T-1;i++){
            if(com2(vec[i],vec[i+1]))
                cout<<vec[i].id+1<<",";
            else
                cout<<vec[i].id+1<<"=";
        }
        cout<<vec[T-1].id+1<<endl;
        vec.clear();
    }
    
}

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(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;
			}
		}
		cout << endl;
	}
	return 0;
}