import Control.Monad
import Control.Applicative
import Control.Monad.State

data Event = HIT | HOMERUN | OUT deriving (Show, Read, Eq)

type EventList = [Event]
type Base = Int
type Outs = Int
type GameCount = (Base, Outs)
type Score = Int
type Scores = [Int]
type GameState = (GameCount, Scores)

addScore :: State GameState Scores
addScore = do
  ((base, outs), score) <- get
  let (now:past) = score
      newScore = (now + 1):past
  put ((base - 1, outs), newScore)
  return newScore

newGame :: State GameState Scores
newGame = do
  ((base, outs), score) <- get
  let newScore = (0:score)
  put ((0, 0), newScore)
  return newScore

hit :: State GameState Scores
hit = do
  ((base, outs), score) <- get
  put ((base + 1, outs), score)
  return score

homerun :: State GameState Scores
homerun = do
  ((base, outs), score) <- get
  let (now:past) = score
      newScore = (now + base + 1):past
  put ((0, outs), newScore)
  return newScore

out :: State GameState Scores
out = do
  ((base, outs), score) <- get
  put ((base, outs + 1), score)
  return score

simulate :: EventList -> State GameState Scores
simulate [] = do
  (_, score) <- get
  return score
simulate (x:xs) = do
  ((base, outs), score) <- get
  case (base, outs, x) of
    (base, outs, x) | outs == 3 -> do
                      newGame
                      simulate (x:xs)
                    | base == 4 -> do
                      addScore
                      simulate (x:xs)
                    | x == HIT -> do
                      hit
                      simulate xs
                    | x == HOMERUN -> do
                      homerun
                      simulate xs
                    | x == OUT -> do
                      out
                      simulate xs

main = do
  getLine
  contents <- map (read :: String -> Event) . lines <$> getContents
  putStr $ unlines $ map show $ reverse $ evalState (simulate contents) ((0, 0), [0])