#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int M, T, P, R;
    while(cin >> M >> T >> P >> R, M){
        vector< pair< pair<int, int>, int> > data(T);
        for(int i = 0 ; i < T ; i++){
            data[i].second = -i;
        }
        vector< vector< pair<bool, int> > > solved(T, vector< pair<bool, int> >(P));
        for(int i = 0 ; i < R ; i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            p--;
            if(j == 0){
                data[t].first.first--;
                data[t].first.second += solved[t][p].second + m;
                solved[t][p].first = true;
            }else if(!solved[t][p].first){
                solved[t][p].second += 20;
            }
        }

        sort(data.begin(), data.end());

        string ans = to_string(-data[0].second + 1);
        for(int i = 1 ; i < T ; i++){
            if(data[i].first == data[i - 1].first){
                ans.push_back('=');
            }else{
                ans.push_back(',');
            }
            ans += to_string(-data[i].second + 1);
        }

        cout << ans << endl;
    }
}
