#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int main(){
	while(true){
		int m,t,p,r;
		scanf("%d%d%d%d",&m,&t,&p,&r);
		if(m==0) break;
		int tim[50][10]={},wa[50][10]={};
		rep(i,50) rep(j,10) tim[i][j]=-1;
		rep(i,r){
			int mm,tt,pp,jj;
			scanf("%d%d%d%d",&mm,&tt,&pp,&jj);
			tt--,pp--;
			if(jj==0) tim[tt][pp]=mm+wa[tt][pp]*20;
			else wa[tt][pp]++;
		}
		int pen[50]={},acp[50]={};
		rep(i,t) rep(j,p){
			if(tim[i][j]==-1) continue;
			acp[i]++;
			pen[i]+=tim[i][j];
		}
		vector<PP> vc;
		rep(i,t) vc.push_back(PP(P(acp[i],-pen[i]),i+1));
		sort(vc.begin(),vc.end(),greater<PP>());
		rep(i,t){
			if(i==0){
				printf("%d",vc[i].second);
				continue;
			}
			if(vc[i].first==vc[i-1].first) printf("=%d",vc[i].second);
			else printf(",%d",vc[i].second);
//			cout << vc[i].second << " acp " << vc[i].first.first << " pen " << vc[i].first.second << endl;
		}
		printf("\n");
	}
	return 0;
}