output_description: For each dataset, your program should output team numbers (from 1 to _T_),
  higher ranked teams first. The separator between two team numbers should be a
  comma. When two teams are ranked the same, the separator between them should
  be an equal sign. Teams ranked the same should be listed in decreasing order
  of their team numbers.
input_description: The input is a sequence of datasets each in the following format. The last
  dataset is followed by a line with four zeros.
  
  > _M_ _T_ _P_ _R_  
  >  _m_ 1 _t_ 1 _p_ 1 _j_ 1  
  >  _m_ 2 _t_ 2 _p_ 2 _j_ 2  
  >  .....  
  >  _m R_ _t R_ _p R_ _j R_  
  >
  
  The first line of a dataset contains four integers _M_ , _T_ , _P_ , and _R_.
  _M_ is the duration of the contest. _T_ is the number of teams. _P_ is the
  number of problems. _R_ is the number of submission records. The relations 120
  ≤ _M_  ≤ 300, 1 ≤ _T_  ≤ 50, 1 ≤ _P_  ≤ 10, and 0 ≤ _R_  ≤ 2000 hold for these
  values. Each team is assigned a team number between 1 and _T_ , inclusive.
  Each problem is assigned a problem number between 1 and _P_ , inclusive.
  
  Each of the following _R_ lines contains a submission record with four
  integers _m k_, _t k_, _p k_, and _j k_ (1 ≤ _k_  ≤ _R_). _m k_ is the elapsed
  time. _t k_ is the team number. _p k_ is the problem number. _j k_ is the
  judgment (0 means correct, and other values mean incorrect). The relations 0 ≤
  _m k_ ≤ _M_ −1, 1 ≤ _t k_ ≤ _T_ , 1 ≤ _p k_ ≤ _P_ , and 0 ≤ _j k_ ≤ 10 hold
  for these values.
  
  The elapsed time fields are rounded off to the nearest minute.
  
  Submission records are given in the order of submission. Therefore, if _i_  <
  _j_ , the _i_ -th submission is done before the _j_ -th submission (_m i_ ≤ _m
  j_). In some cases, you can determine the ranking of two teams with a
  difference less than a minute, by using this fact. However, such a fact is
  never used in the team ranking. Teams are ranked only using time information
  in minutes.
attempt: while True:
      M, T, P, R = map(int, input().split())
      if M == 0 and T == 0 and P == 0 and R == 0:
          break
      teams = [[0, 0, [0 for _ in range(P)], i + 1] for i in range(T)]
      solved, time, miss = 0, 1, 2
      logs = [map(int, input().split()) for _ in range(R)]
      for m, t, p, r in logs:
          t -= 1
          p -= 1
          if r == 0:
              teams[t][solved] += 1
              teams[t][time] -= m + teams[t][miss][p] * 20
          else:
              teams[t][miss][p] += 1
      teams = sorted(teams, reverse=True)
      before_s, before_t = 0, 0
      for i in range(T):
          s, t, _, n = teams[i]
          if i != 0:
              print("=" if (s == before_s and t == before_t) else ",", end="")
          before_s, before_t = s, t
          print(n, end="")
      print("")
  
problem_description: ICPC Ranking
  
  Your mission in this problem is to write a program which, given the submission
  log of an ICPC (International Collegiate Programming Contest), determines team
  rankings.
  
  The log is a sequence of records of program submission in the order of
  submission. A record has four fields: elapsed time, team number, problem
  number, and judgment. The elapsed time is the time elapsed from the beginning
  of the contest to the submission. The judgment field tells whether the
  submitted program was correct or incorrect, and when incorrect, what kind of
  an error was found.
  
  The team ranking is determined according to the following rules. Note that the
  rule set shown here is one used in the real ICPC World Finals and Regionals,
  with some detail rules omitted for simplification.
  
    1. Teams that solved more problems are ranked higher. 
    2. Among teams that solve the same number of problems, ones with smaller total consumed time are ranked higher. 
    3. If two or more teams solved the same number of problems, and their total consumed times are the same, they are ranked the same. 
  
  The total consumed time is the sum of the consumed time for each problem
  solved. The consumed time for a solved problem is the elapsed time of the
  accepted submission plus 20 penalty minutes for every previously rejected
  submission for that problem.
  
  If a team did not solve a problem, the consumed time for the problem is zero,
  and thus even if there are several incorrect submissions, no penalty is given.
  
  You can assume that a team never submits a program for a problem after the
  correct submission for the same problem.
samples: [{"input": "10 8 5\n    50 5 2 1\n    70 5 2 0\n    75 1 1 0\n    100 3 1 0\n    150 3 2 0\n    240 5 5 7\n    50 1 1 0\n    60 2 2 0\n    70 2 3 0\n    90 1 3 0\n    120 3 5 0\n    140 4 1 0\n    150 2 4 1\n    180 3 5 4\n    15 2 2 1\n    20 2 2 1\n    25 2 2 0\n    60 1 1 0\n    120 5 5 4\n    15 5 4 1\n    20 5 4 0\n    40 1 1 0\n    40 2 2 0\n    120 2 3 4\n    30 1 1 0\n    40 2 1 0\n    50 2 2 0\n    60 1 2 0\n    120 3 3 2\n    0 1 1 0\n    1 2 2 0\n    300 5 8 0\n    0 0 0 0", "output": ",1,5,10=9=8=7=6=4=2\n    2,1,3,4,5\n    1,2,3\n    5=2=1,4=3\n    2=1\n    1,2,3\n    5=4=3=2=1"}]