#include<bits/stdc++.h>
#define f first 
#define sf second.first 
#define ss second.second 
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P > iP;

int main(){
  int t,p,r,b;
  while(cin>>b>>t>>p>>r&&t){
    iP a[51];
    int k[11][51]={};
    a[0]=iP(-1,P(-1,-1));
    for(int i=1;i<=t;i++)a[i]=iP(0,P(0,i));
    for(int i=0;i<r;i++){
      int ti,pi,m,s;
      cin>>m>>ti>>pi>>s;
      if(!s)a[ti].f++,a[ti].sf-=m+k[pi][ti]*20;
      else k[pi][ti]++;
    }
    sort(a+1,a+t+1);
    for(int i=t;i>0;i--){
      cout<<a[i].ss;
      if(i!=1)
	if(a[i-1].f==a[i].f&&a[i-1].sf==a[i].sf)cout<<"=";
	else cout<<",";
    }
    cout<<endl;
  }
  return 0;
}