using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    struct Team
    {
        public int sum_time;
        public int solve_pro_num;
        public Problem[] pro_data;
        public int team_number;

        public Team(int P, int sum_time, int solve_pro_num, int num)
        {
            pro_data = new Problem[P];
            this.sum_time = sum_time;
            this.solve_pro_num = solve_pro_num;
            team_number = num;
            for(int i = 0; i < P; i++)
            {
                pro_data[i] = new Problem(0, 0, 1);
            }
        }      
    }

    struct Problem
    {
        public int num_submit;
        public int last_solved_time;
        public int result;

        public Problem(int n, int f, int r)
        {
            num_submit = n;
            last_solved_time = f;
            result = r;
        }
    }

    class Contest
    {
        int num_of_pro;
        int num_of_team;
        int open_period;        
        public Team[] team_data;

        public Contest(int M, int T, int P)
        {
            num_of_pro = P;
            num_of_team = T;
            open_period = M;
            CreateTeamStruct(T, P);
        }

        void CreateTeamStruct(int T, int P)
        {
            team_data = new Team[T];
            for(int i = 0; i < T; i++)
            {
                team_data[i] = new Team(P, 0, 0, i + 1);
            }
        }

        //問題の提出回数、結果、最終提出時間、チームの正解回数を更新
        public void Updata_Team_Data(int time, int team, int pro, int result)
        {            
            team_data[team].pro_data[pro].result = result;
            team_data[team].pro_data[pro].num_submit++;
            team_data[team].pro_data[pro].last_solved_time = time;
            if(result == 0)
            {
                team_data[team].solve_pro_num++;
            }
        }

        public void Calc_AllTeam_SumTime()
        {

            for(int i = 0; i < num_of_team; i++)
            {
                for(int j = 0; j < num_of_pro; j++)
                {
                    //解けていたらペナルティーを付加してチームの合計所要時間に加算
                    if(team_data[i].pro_data[j].result == 0)
                    {
                        int sub_num = team_data[i].pro_data[j].num_submit;
                        int last_time = team_data[i].pro_data[j].last_solved_time;
                        team_data[i].sum_time += last_time + 20 * (sub_num - 1);
                    }
                }
            }

        }

        public void Show_Ranking()
        {
            Calc_AllTeam_SumTime();

            var team_data_sorted = team_data.OrderByDescending(x => x.solve_pro_num).ThenBy(x => x.sum_time).ThenByDescending(x => x.team_number).ToArray();

            int old_solve_num = team_data_sorted[0].solve_pro_num;
            int old_sum_time = team_data_sorted[0].sum_time;
            int old_team = team_data_sorted[0].team_number;
            Console.Write(old_team);
            for(int i = 1; i < num_of_team; i++)
            {
                string head_str;

                if(team_data_sorted[i].solve_pro_num == old_solve_num && team_data_sorted[i].sum_time == old_sum_time)
                {
                    head_str = "=";
                }
                else
                {
                    head_str = ",";
                }

                old_solve_num = team_data_sorted[i].solve_pro_num;
                old_sum_time = team_data_sorted[i].sum_time;
                old_team = team_data_sorted[i].team_number;

                Console.Write(head_str + team_data_sorted[i].team_number.ToString());

            }

            Console.WriteLine();

        }
        
    }
    

    class Program
    {
        
        
        static void Main(string[] args)
        {

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int M = int.Parse(input[0]);
                int T = int.Parse(input[1]);
                int P = int.Parse(input[2]);
                int R = int.Parse(input[3]);

                if(M == 0 && T == 0 && P == 0 && R == 0)
                {
                    break;
                }

                Contest contest = new Contest(M, T, P);

                for(int i = 0; i < R; i++)
                {
                    int[] sub_data = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                    contest.Updata_Team_Data(sub_data[0], sub_data[1] - 1, sub_data[2] - 1, sub_data[3]);
                }

                contest.Show_Ranking();
              
            }
            
        }
    }
}


Measured memory_bytes: 24492