#include<bits/stdc++.h>
using namespace std;
struct Data{

  int team;
  int c_num;
  int w_num[11];
  int time;

  bool operator<(const Data& data)const{
    if(data.c_num != c_num)return c_num > data.c_num;
    if(data.time != time)return time < data.time;
    return team > data.team;
  }
  
};
void Init(Data *data,int T,int P){

  for(int i=1 ; i <= T ; i++){
    data[i].team=i;
    data[i].c_num=0;
    data[i].time=0;
    for(int j=1 ; j <= P ; j++){
      data[i].w_num[j]=0;
    }
  }
  
}
bool isSame(Data *data,int a,int b){

  if(data[a].c_num == data[b].c_num && data[a].time == data[b].time)return true;

  return false;
  
}
int main(){
  
  int M,T,P,R;
  
  while(1){

    cin >>M>>T>>P>>R;
    if(M==0 && T==0 && P==0 && R==0)break;

    Data data[T+1];
    Init(data,T,P);
    
    int m,t,p,j;
    for(int i=0 ; i < R ; i++){
      cin >>m>>t>>p>>j;
      if(j == 0){
	data[t].c_num++;
	data[t].time+=m+20*data[t].w_num[p];
      }else{
	data[t].w_num[p]++;
      }
    }

    sort(data+1,data+T+1);

    for(int i=1 ; i <= T ; i++){
      cout <<data[i].team;
      if(i+1 <= T){
	if(isSame(data,i,i+1)){
	  cout <<"="; 
	}else{
	  cout <<",";
	}
      }
    }
    cout <<endl;
    
  }
  
  return 0;
}