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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

struct Team{
public:
  int solved;
  int elapsed_time;
  int penalty;
  int id;
  Team() : solved(0),elapsed_time(0),penalty(0),id(0){}
  bool operator<(const Team& t) const{
    if(__builtin_popcount(solved) == __builtin_popcount(t.solved)){
      if((elapsed_time + penalty) == (t.elapsed_time + t.penalty)){
	return id > t.id;
      }
      else{
	return ((elapsed_time + penalty) < (t.elapsed_time + t.penalty)); 
      }
    }
    else{
      return (__builtin_popcount(solved) > __builtin_popcount(t.solved));
    }
  }
  bool operator>(const Team& t) const{
    if(__builtin_popcount(solved) == __builtin_popcount(t.solved)){
      if((elapsed_time + penalty) == (t.elapsed_time + t.penalty)){
	return id > t.id;
      }
      else{
	return ((elapsed_time + penalty) > (t.elapsed_time + t.penalty)); 
      }
    }
    else{
      return (__builtin_popcount(solved) > __builtin_popcount(t.solved));
    }
  }
  bool operator==(const Team& t) const{
    if(__builtin_popcount(solved) == __builtin_popcount(t.solved)
       && (elapsed_time + penalty) == (t.elapsed_time + t.penalty)){
      return true;
    }
    return false;
  }
};

int main(){
  int duration;
  int total_teams;
  int total_problems;
  int total_submission_records;
  while(~scanf("%d %d %d %d",
	       &duration,
	       &total_teams,
	       &total_problems,
	       &total_submission_records)){

    if(duration == 0
       && total_teams == 0
       && total_problems == 0
       && total_submission_records == 0) break;

    Team teams[51];
    int freq[51][11];
    
    memset(freq,0,sizeof(freq));
    for(int team_idx=0;team_idx < total_teams; team_idx++){
      teams[team_idx].id = team_idx+1;
    }
    for(int submit_idx=0;submit_idx< total_submission_records; submit_idx++){
      int elapsed_time;
      int team_number;
      int problem_number;
      int judgement;
      scanf("%d %d %d %d",
	    &elapsed_time,
	    &team_number,
	    &problem_number,
	    &judgement);
      if(judgement == 0){
	teams[team_number-1].elapsed_time
	  += elapsed_time;
	teams[team_number-1].penalty
	  += freq[team_number-1][problem_number-1] * 20;
	freq[team_number-1][problem_number-1] = 0;
	teams[team_number-1].solved |= (1<<(problem_number-1));
      }
      else{
	if(!(teams[team_number-1].solved & (1<<(problem_number-1)))){
	  freq[team_number-1][problem_number-1]++;
	}
      }
    }

    sort(teams,teams+total_teams);
    for(int team_idx=0;team_idx+1 < total_teams; team_idx++){
      if(teams[team_idx] == teams[team_idx+1]){
	printf("%d=",teams[team_idx].id);
      }
      else{
	printf("%d,",teams[team_idx].id);
      }
    }
    printf("%d\n",teams[total_teams-1].id);
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int M, T, P, R;
int m[2003], t[2003], p[2003], j[2003];
int correct[51], penalty[51][11], times[51][11];
int is_correct[51][11];
void solve() {
    memset(correct, 0, sizeof(correct));
    memset(penalty, 0, sizeof(penalty));
    memset(times, 0, sizeof(times));
    memset(is_correct, 0, sizeof(is_correct));
    rep(i, R) {
        if (j[i] == 0) {
            if (is_correct[t[i]][p[i]]) continue;
            is_correct[t[i]][p[i]] = 1;
            correct[t[i]]++;
            times[t[i]][p[i]] += m[i];
            times[t[i]][p[i]] += penalty[t[i]][p[i]] * 20;
        } else {
            penalty[t[i]][p[i]]++;
        }
    }
    vector<tuple<int, int, int>> vec;
    rep(i, T) {
        int sum = 0;
        rep(k, P) sum += times[i][k];
        vec.emplace_back(-correct[i], sum, -i);
    }
    sort(all(vec));
    tuple<int, int, int> pre{-1, -1, -1};
    rep(i, vec.size()) {
        auto x = vec[i];
        if (get<0>(x) == get<0>(pre) and get<1>(x) == get<1>(pre)) {
            cout << "=";
        } else {
            if (i) cout << ",";
        }
        cout << -get<2>(x) + 1;

        pre = x;
    }
    cout << endl;
}
int main() {
    while (cin >> M >> T >> P >> R, M) {
        rep(i, R) cin >> m[i] >> t[i] >> p[i] >> j[i];
        rep(i, R) t[i]--;
        solve();
    }
    return 0;
}