#include <bits/stdc++.h>

using namespace std;

#define MAX_R 2005

typedef pair<int,int> PA;

int M,T,P,R;

int m,t,p,j;

int main(){
    while(1){
        cin >> M >> T >> P >> R;
        if(M==0 && T == 0 && P==0&&R==0)break;
        vector<int> solve(T);
        vector<int> time(T);
        int miss[51][11]={};
        for(int i=0;i<R;i++){
            cin >> m >> t >> p >> j;
            if(j == 0){
                solve[t-1]++;
                time[t-1] += m + miss[t-1][p] * 20;
            }else{
                miss[t-1][p] ++;
            }
        }

        vector<PA> ans1(T);
        vector<PA> ans2(T);
        for(int i=0;i<T;i++){
            ans1[i] = make_pair(solve[i],i+1);
            ans2[i] = make_pair(time[i],i+1);
        }
        
        sort(ans1.begin(),ans1.end());
        sort(ans2.begin(),ans2.end());
        for(int s=0;s<T;s++){
            for(int i=T-1;i>0;i--){
                if(ans1[i].first > ans1[i-1].first){
                }else if(ans1[i].first == ans1[i-1].first){
                    int a,b;
                    a=b=0;
                    for(int j=0;j<T;j++){
                        if(ans2[j].second == ans1[i].second){
                            a = ans2[j].first;
                        }
                        if (ans2[j].second == ans1[i-1].second){
                            b = ans2[j].first;
                        }
                        if(a != 0 && b== 0){
                            break;
                        }
                        if(a == 0 && b != 0){
                            swap(ans1[i].first,ans1[i-1].first);
                            swap(ans1[i].second,ans1[i-1].second);
                            break;
                        }
                    }
                }
            }
        }
        for(int s=0;s<T;s++){
            for(int i=T-1;i>=0;i--){
                if(i==T-1)continue;
                else{
                    if(ans1[i+1].first == ans1[i].first){
                        int a,b;
                        for(int j=0;j<T;j++){
                            if(ans2[j].second == ans1[i].second){
                                a = ans2[j].first;
                            }
                            if (ans2[j].second == ans1[i+1].second){
                                b = ans2[j].first;
                            }
                        }
                        if(a==b && ans1[i+1].second < ans1[i].second){
                            swap(ans1[i].first,ans1[i+1].first);
                            swap(ans1[i].second,ans1[i+1].second);
                        }
                    }
                }
            }
        }
        
        for(int i=T-1;i>=0;i--){
            if(i==T-1){
                printf("%d",ans1[i].second);
            }
            else{
                if(ans1[i+1].first > ans1[i].first){
                    printf(",%d",ans1[i].second);
                }else if(ans1[i+1].first == ans1[i].first){
                    int a,b;
                    for(int j=0;j<T;j++){
                        if(ans2[j].second == ans1[i].second){
                            a = ans2[j].first;
                        }
                        if (ans2[j].second == ans1[i+1].second){
                            b = ans2[j].first;
                        }
                    }
                    if(a==b){
                        printf("=%d",ans1[i].second);
                    }else{
                        printf(",%d",ans1[i].second);
                    }
                    
                }
            }
            
        }
        puts("");
        
    }
}


Measured memory_bytes: 3144