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<cstdlib>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

class results {
public:
  int orgNum;
  int tTime;
  int tSolved;

  bool operator<(const results& right) const {
    if(tSolved < right.tSolved) {
      return 0;
    }
    else if(tSolved > right.tSolved) {
      return 1;
    }
    else {
      if(tTime < right.tTime) {
	return 1;
      }
      else if(tTime > right.tTime) {
	return 0;
      }
      else {
	if(orgNum > right.orgNum) {
	  return 1;
	}
	else {
	  return 0;
	}
      }
    }
  };

  void init(int num) {
    orgNum = num;
    tTime = 0;
    tSolved = 0;
  }
  void update(int t) {
    tTime += t;
    tSolved += 1;
  }
};

class problems {
public:
  int pTime;
  int pSolved;

  void init() {
    pTime = 0;
    pSolved = 0;
  }
  void init(int t, int s) {
    if(s == 0) {
      pTime = t;
      pSolved = 1;
    }
    else {
      pTime = 20;
      pSolved = 0;
    }
  }
  void update(int t, int s) {
    //pTime += t;
    if(s == 0) {
      pTime += t;
      pSolved = 1;
    }
    else {
      pTime += 20;
    }
  }
};

int main() {
  int m, t, p, r;
  while(cin>>m>>t>>p>>r && m>0) {
    map<pair<int, int>, problems> inputs;
    int tmpM, tmpT, tmpP, tmpJ;
    for(int i=0; i<r; i++) {
      cin>>tmpM>>tmpT>>tmpP>>tmpJ;
      tmpT--;
      tmpP--;
      if(!inputs.count(make_pair(tmpT, tmpP))) {
	problems tmpData;
	tmpData.init(tmpM, tmpJ);
	inputs.insert(make_pair(make_pair(tmpT, tmpP), tmpData));
      }
      else {
	inputs[make_pair(tmpT, tmpP)].update(tmpM, tmpJ);
      }
    }

    vector<results> ans;
    for(int i=0; i<t; i++) { // team
      results tmp;
      tmp.init(i);
      //for(int j=0; j<inputs.size(); j++) { // problem
      for(int j=0; j<p; j++) {
	map<pair<int, int>, problems>::iterator itr;
	//auto itr = inputs.find(make_pair(i,j)); // C++11
	itr = inputs.find(make_pair(i,j)); // チーム i の問題 j を確認
	if(itr != inputs.end()) {
	  if(inputs[itr->first].pSolved == 1) { // ???
	    tmp.update(inputs[itr->first].pTime);
	  }
	}
      }
      //cout<<tmp.orgNum<<" "<<tmp.tSolved<<" "<<tmp.tTime<<endl;
      ans.push_back(tmp);
    }

    // print
    /*
    for(int i=0; i<ans.size(); i++) {
      cout<<ans[i].orgNum<<" "<<ans[i].tSolved<<" "<<ans[i].tTime<<endl;
    }
    */

    sort(ans.begin(), ans.end());
    /*
    for(int i=0; i<ans.size(); i++) {
      cout<<ans[i].orgNum<<" "<<ans[i].tSolved<<" "<<ans[i].tTime<<endl;
    }
    */

    for(int i=0; i<ans.size()-1; i++) {
      cout<<ans[i].orgNum+1;
      if(ans[i].tSolved==ans[i+1].tSolved && ans[i].tTime==ans[i+1].tTime) {
	cout<<"=";
      }
      else {
	cout<<",";
      }
    }
    //int tmp = ans.size();
    cout<<ans[ans.size()-1].orgNum+1<<endl;
  }
}

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

const int MAX_T = 55;
const int MAX_P = 11;

bool is_correct[MAX_T][MAX_P];
int correct_cnt[MAX_T];
int penalty_record[MAX_T][MAX_P];
int elapsed[MAX_T];

bool cmp(const int& team1, const int& team2) {
    if (correct_cnt[team1] != correct_cnt[team2]) {
        return correct_cnt[team1] > correct_cnt[team2];
    }
    else {
        if (elapsed[team1] != elapsed[team2]) {
            return elapsed[team1] < elapsed[team2];
        }
        return team1 > team2;
    }
}

void solve(int M, int T, int P, int R) {
    for (int i = 1; i <= T; i++) {
        correct_cnt[i] = 0;
        elapsed[i] = 0;
        for (int j = 1; j <= P; j++) {
            penalty_record[i][j] = 0;
            is_correct[i][j] = false;
        }
    }
    int m, t, p, j;
    for (int i = 0; i < R; i++) {
        cin >> m >> t >> p >> j;
        if (j == 0) {
            correct_cnt[t]++;
            is_correct[t][p] = true;
            elapsed[t] += m + 20 * penalty_record[t][p];
        }
        else {
            penalty_record[t][p]++;
        }
    }
    vector<int> ans;
    for (int i = 1; i <= T; i++) {
        ans.push_back(i);
    }
    sort(ans.begin(), ans.end(), cmp);
    for (int i = 0; i < ans.size() - 1; i++) {
        cout << ans[i];
        if (correct_cnt[ans[i]] != correct_cnt[ans[i + 1]]) {
            cout << ',';
        }
        else {
            if (elapsed[ans[i]] != elapsed[ans[i + 1]]) {
                cout << ',';
            }
            else cout << '=';
        }
    }
    cout << ans[ans.size() - 1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, T, P, R;
    while (true) {
        cin >> M >> T >> P >> R;
        if (M == 0 && T == 0 && P == 0 && R == 0) break;
        solve(M, T, P, R);
    }
    return 0;
}