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>
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[T],  TT[T],  PT[T][P]; //正解数、時間計、ペナルティ
  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, j;
   cin >> m >> t >> p >> j;
   
   if(j==0){ //正解
    CP[t-1]++;
    TT[t-1] += (m+PT[t-1][p-1]);
   }else{ //不正解
    PT[t-1][p-1] += 20;
   }
  }

   int t_now, t_pre = -1; //今のチーム、1つ前のチーム
   bool flag[50]; //処理済みフラグ
   for(int i=0; i<T; i++){
    flag[i] = false;
   }
   
   for(int i=0; i<T; i++){
    t_now = -1;
    for(int j=0; j<T; j++){ //今のチームを求める
     if(flag[j]) continue;
     if(t_now==-1){
      t_now = j;
     }else{
      if(CP[j]>CP[t_now] || (CP[j]==CP[t_now] && TT[j]<=TT[t_now])){
       t_now = j;
      }
     }
    }

    if(t_pre!=-1){
     if(CP[t_now]==CP[t_pre] && TT[t_now]==TT[t_pre]){
      cout << '=';
     }else{
      cout << ',';
     }
    }
    cout<<t_now+1;

    flag[t_now] = true;
    t_pre = t_now;
   }
   cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

typedef pair<long, int> pr; // first: pts, second: team number;

int penalty[50][10]; // [team][problem number]
pr pts[50];
priority_queue<int> list;
int m, t, p, r;

int printout(int n, long pre) {
	if (n < t && pre == pts[n].first) {
		list.push(pts[n].second);
		return printout(n+1, pre);
	} else {
		int size = list.size();
		if (size == 0) return 1;
		while (true) {
			cout << list.top();
			list.pop();
			if (list.empty()) break;
			cout << "=";
		}
		return size;
	}

	cout << "ERR" << endl;
	return 0;
}

int main() {
	while (true) {
		cin >> m >> t >> p >> r;
		if (m == 0 && t == 0 && p == 0 && r == 0) break;

		for (int i = 0; i < t; ++i) {
			pts[i].second = i+1;
			pts[i].first = 0;
			for (int j = 0; j < p; ++j)
				penalty[i][j] = 0;
		}
		for (int i = 0; i < r; ++i) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if (d == 0) {
				pts[b-1].first += -10000 + a + penalty[b-1][c-1];
			} else {
				penalty[b-1][c-1] += 20;
			}
		}

		sort(pts, pts + t);
		int i = 0;
		while (true) {
			i += printout(i, pts[i].first);
			if (i >= t)
				break;
			cout << ",";
		}
		cout << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int M, T, P, R;

struct data{
    int id, ac, pe;
};

bool cmp(data d1, data d2){
    if(d1.ac == d2.ac){
        if(d1.pe == d2.pe) return d1.id > d2.id;
        return d1.pe < d2.pe;
    }
    return d1.ac > d2.ac;
}

int main(){
    while(1){
        cin >> M >> T >> P >> R;
        if(M + T + P + R == 0) break;
        int wa[51][11] = {};
        vector<data> d(T);
        rep(i, 0, T) d[i].id = i;
        rep(i, 0, R){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            if(j != 0){
                wa[t][p]++;
            }else{
                d[t].ac++;
                d[t].pe += m + 20 * wa[t][p];
            }
        }
        // rep(i, 0, T){
        //     cout << d[i].id << " " << d[i].ac << " " << d[i].pe << endl;
        // }
        sort(d.begin(), d.end(), cmp);        
        rep(i, 0, T){
            if(i != 0 && d[i].ac == d[i - 1].ac && d[i].pe == d[i - 1].pe){
                cout << "=";
            }else if(i != 0){
                cout << ",";
            }
            cout << d[i].id + 1;
        }
        cout << endl;
    }
}

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

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

struct State{
  int solve, id, time;
  map<int, int> wrong;
  
  State(): solve(0), id(0), time(0) {}
  
  bool operator< (const State &a) const{
    if(solve == a.solve){
      if(time == a.time){
	return id > a.id;
      }
      else return time < a.time;
    }
    else return solve > a.solve;
  }
};

int main(){
  int M, T, P, R;
  while(cin >> M >> T >> P >> R, M|T|P|R){
    vector<State> res;
    for(int i = 1 ; i <= T ; i++){
      State tmp;
      tmp.id = i;
      res.push_back(tmp);
    }
    
    int m, t, p, ac;
    rep(i, R){
      cin >> m >> t >> p >> ac;
      t--;
      if(ac == 0){
	res[t].solve++;
	res[t].time += m + res[t].wrong[p]*20;
      }
      else{
	res[t].wrong[p]++;
      }
    }
    sort(res.begin(), res.end());
    
    for(int i = 0 ; i < res.size() ; i++){
      cout << res[i].id;
      if(i == res.size()-1){
	cout << endl;
      }
      else if(res[i].solve == res[i+1].solve && res[i].time == res[i+1].time){
	cout << '=';
      }
      else cout << ',';      
    }
  }  
  return 0;
}