#include <iostream>
#define INF 10e6
using namespace std;

int M,T,P,R;
int m,t,p,j;
bool flag[50];

bool check(){
	for(int i=0;i<T;i++)
		if(flag[i])
			return true;
	return false;
}

int main(void){
	int team[50][2];
	bool problem[50][10];
	int  time[50][10];
	while(cin >> M >> T >> P >> R,M){
		for(int i=0;i<T;i++)
			team[i][0]=team[i][1]=0,flag[i]=true;
		for(int i=0;i<T;i++)
			for(int j=0;j<P;j++)
				problem[i][j]=false,time[i][j]=0;

		for(int i=0;i<R;i++){
			cin >> m >> t >> p >> j;
			if(j)
				time[t-1][p-1]+=20;
			else
				problem[t-1][p-1]=true,time[t-1][p-1]+=m;
		}
			
		for(int i=0;i<T;i++){
			for(int j=0;j<P;j++){
				if(problem[i][j]){
					team[i][0]++;
					team[i][1]+=time[i][j];
				}
			}
		}
		
		int d=0;
		while(check()){
			cout <<( d ? "," :"") ;
			d++;
			int cor=0,less=INF,c=0;
			for(int i=T-1;i>=0;i--){
				if(flag[i]&&(team[i][0]>cor))
					cor=team[i][0],less=team[i][1];
				else if(flag[i]&&team[i][0]==cor&&team[i][1]<less)
					less=team[i][1];
			}
			for(int i=T-1;i>=0;i--)
				if(flag[i]&&team[i][0]==cor&&team[i][1]==less)
					flag[i]=false, cout<< (c? "=":"") << i+1,c++;
		
		}
		cout << endl;
	}
	return 0;
}