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++: #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;


int main()
{
	int M, T, P, R;
	while (cin >> M >> T >> P >> R,M)
	{
		vector<vector<int>>data;
		vector<pair<int,pair<int,int>>>ans;
		data.resize(T);
		ans.resize(T);
		for (size_t i = 0; i < T; i++)
		{
			ans[i] = pair < int, pair<int,int> > {i, pair < int, int > {0, 0}};
			data[i].resize(P);
		}
		int a, b, c, d;
		for (size_t i = 0; i < R; i++)
		{
			cin >> a >> b >> c >> d;
			b--;
			c--;
			if (d)
			{
				data[b][c]+=1;
			}
			else
			{
				ans[b].second.first++;
				ans[b].second.second += data[b][c]*20+a;
			}
		}
		sort(ans.begin(), ans.end(), [](const pair<int,pair<int, int>>a, const pair<int,pair<int, int>>b) {
			if (a.second.first == b.second.first)
			{
				if (a.second.second == b.second.second)
				{
					return a.first > b.first;
				}
				return (a.second.second < b.second.second);
			} else return a.second.first > b.second.first;
		});
		
		cout << ans[0].first+1;
		for (size_t i = 1; i < T; i++)
		{
			if (ans[i - 1].second.first == ans[i].second.first&&ans[i - 1].second.second == ans[i].second.second)
			{
				cout << '=';
			} else
			{
				cout << ',';
			}
			cout << ans[i].first+1;
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int m,t,p,r;
  while(cin>>m>>t>>p>>r,m+t+p+r){
    pair<int,int>pii[t+10][p+10];
    for(int i=0;i<t+10;i++)
      for(int j=0;j<p+10;j++)
	pii[i][j]=mp(-1,0);
    for(int i=0;i<r;i++){
      int a,b,c,d;cin>>a>>b>>c>>d;
      b--;c--;
      if(d==0)
	pii[b][c].F=a;
      else
	pii[b][c].S+=20;
    }
    vector<pair<int,pair<int,int> > >team(t+10);
    for(int i=0;i<t;i++)
      team[i]=mp(0,mp(INF,i+1));
    for(int i=0;i<t;i++){
      for(int j=0;j<p+10;j++){
	if(pii[i][j].F>=0){
	  team[i].S.F-=pii[i][j].F+pii[i][j].S;
	  team[i].F++;
	}
      }
    }
    sort(team.begin(),team.end(),greater<pair<int,pair<int,int> > >());
    for(int i=0;i<t;i++){
      if(i==0)
	cout<<team[i].S.S;
      else{
	if(team[i].F==team[i-1].F&&team[i-1].S.F==team[i].S.F){
	  cout<<"=";
	}else{
	  cout<<",";
	}
	cout<<team[i].S.S;
      }
    }
    cout<<endl;
  }
  return 0;
}