#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define F first
#define S second
using namespace std;

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M){
		pair<int,pair<int,int>> ans[51];//-nans,time,team
		int pena[51][11]={0};//team,mondai
		REP(i,1,T+1){
			ans[i].F=0;
			ans[i].S.F=0;
			ans[i].S.S=-i;
		}

		REP(i,0,R){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j){//WA
				pena[t][p]++;
			}else{//AC
				ans[t].F--;
				ans[t].S.F+=m+pena[t][p]*20;
			}
		}
		sort(ans+1,ans+T+1);
		cout<<-ans[1].S.S;
		REP(i,2,T+1){
			if(ans[i-1].F==ans[i].F&&ans[i-1].S.F==ans[i].S.F){
				cout<<"="<<-ans[i].S.S;
			}else{
				cout<<","<<-ans[i].S.S;
			}
		}
		p("");
	}

	return 0;
}