#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Team
{
	int id;
	int crr_num;
	int time_sum;
	int fal[10];

	bool operator < (const Team& oth)const{
		if(crr_num==oth.crr_num) {
			if(time_sum==oth.time_sum) return id>oth.id;
			return time_sum<oth.time_sum;
		}
		return crr_num>oth.crr_num;
	}
};

int main(int argc, char const *argv[])
{
	int m,t,p,r;

	while(1){
		cin>>m>>t>>p>>r;
		if(m+t+p+r==0) break;

		vector<Team> jg(t);

		for(int i1=0;i1<t;i1++){
			jg[i1].id=i1+1;
			jg[i1].crr_num=0;
			jg[i1].time_sum=0;
			for(int i2=0;i2<10;i2++){
				jg[i1].fal[i2]=0;
			}
		}

		int tm,tt,tp,j;
		for(int i1=0;i1<r;i1++){
			cin>>tm>>tt>>tp>>j;

			if(j==0){
				jg[tt-1].crr_num++;
				jg[tt-1].time_sum+=(tm+jg[tt-1].fal[tp-1]*20);
			}
			else jg[tt-1].fal[tp-1]++;
		}

		sort(jg.begin(),jg.end());

		cout<<jg[0].id;
		for(int i1=1;i1<t;i1++){
			if(jg[i1].crr_num==jg[i1-1].crr_num && jg[i1].time_sum==jg[i1-1].time_sum){
				cout<<"="<<jg[i1].id;
			}
			else cout<<","<<jg[i1].id;
		}
		cout<<endl;

	}
	return 0;
}