import Control.Monad        -- unless, replicateM
import Control.Applicative  -- <$>
import Data.List            -- sort, group

main :: IO ()
main = do
  [m,t,p,r] <- (map read . words) <$> getLine
  unless (m == 0 && t == 0 && p == 0 && r == 0) $ do
    ds <- replicateM r ((map read . words) <$> getLine)
    putStrLn . ranking t $ ds
    main

{-
   [[m,t,p,j] | m - elapsed time
                t - team
                p - problem
                j - judge (0 = accepted)]
 -}
type Log = [[Int]]

-- Result team solved total
data Result = Result Int Int Int deriving Show
instance Eq Result where
  (Result t s total) == (Result t' s' total') = s == s' && total == total'
instance Ord Result where
  compare (Result t s total) (Result t' s' total')
    | s > s' = LT
    | s < s' = GT
    | total < total' = LT
    | total > total' = GT
    | otherwise = EQ


ranking ::  Int -> Log -> String
ranking nt ds = join ',' . map (join '=' . reverse . map (show . team)) .
  group . sort $ [accum t ds | t<-[1..nt]]
  where
    team (Result t s total) = t
    join :: Char -> [String] -> String
    join c [x]    = x
    join c (x:xs) = x ++ [c] ++ join c xs

accum :: Int -> Log -> Result
accum team ds = Result team (length solved) total
  where
    ts      = [d | d<-ds, d!!1 == team]   -- log for the team
    correct = [d | d<-ts, d!!3 == 0]      -- accepted submissions
    wrong   = [d | d<-ts, d!!3 /= 0]
    solved  = map (!!2) correct           -- solved problems
    consumed p =                          -- consumed time for a problem
      head [d!!0 | d<-correct, d!!2 == p]
      + (length [d | d<-wrong, d!!2 == p]) * 20
    total   = sum . map consumed $ solved -- total consumed time