#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

typedef pair<int,int> pii;
typedef pair<pii,int> piii;

piii mk(int a, int b, int c){
	return piii(pii(a,b), c);
}

int main(){
	A:;
	
	int teemwrong[55][11]={0};
	int teemcost[55]={0};
	int teemac[55]={0};
	
	int M,T,P,R;
	cin>>M>>T>>P>>R;
	
	if(M==0&&T==0&&R==0&&P==0)return 0;
	
	rep(i,R){
		int m,t,p,j;
		cin>>m>>t>>p>>j;
		
		if(j==0){
			teemac[t]++;
			teemcost[t]+=m+teemwrong[t][p]*20;
		}else{
			teemwrong[t][p]++;
		}
	}
	
	vector<piii> rank;
	reps(i,1,T+1){
		rank.push_back(mk(teemac[i], -teemcost[i], i));
	}
	
	sort(rank.begin(),rank.end());
	reverse(rank.begin(),rank.end());
	
	rep(i,rank.size()){
		if(i!=0){
			if(rank[i].first==rank[i-1].first)printf("=");
			else printf(",");
		}
		printf("%d",rank[i].second);
	}puts("");
	
	
	goto A;
}