import Control.Monad
import Control.Monad.State

data BaseBallState = BBS { first :: Int
                         , second :: Int
                         , third :: Int
                         , outCount :: Int
                         , point :: Int
                         } deriving Show

main = do
    n <- readLn
    commandSet <- replicateM n $ getUntil3Out 0 []
    mapM_ print $ map (\commands -> evalState (moveGame commands) (BBS 0 0 0 0 0)) commandSet

getUntil3Out :: Int -> [String] -> IO [String]
getUntil3Out n cs = do
    if n == 3 then return cs
              else do
                  c <- getLine
                  if c == "OUT" then getUntil3Out (n+1) cs
                                else getUntil3Out n (cs ++ [c])

moveGame :: [String] -> State BaseBallState Int
moveGame []     = do
    bbs <- get
    return $ point bbs
moveGame (c:cs) = do
    bbs <- get
    doEvent c
    moveGame cs

doEvent :: String -> State BaseBallState Int
doEvent command = case command of
                    "HIT" -> hit
                    "HOMERUN" -> homerun

hit :: State BaseBallState Int
hit = do
    bbs <- get
    put $ BBS { first = 1
              , second = first bbs
              , third = second bbs
              , outCount = outCount bbs
              , point = point bbs + third bbs
              }
    return $ point bbs + third bbs

homerun :: State BaseBallState Int
homerun = do
    bbs <- get
    put $ BBS { first = 0
              , second = 0
              , third = 0
              , outCount = outCount bbs
              , point = point bbs + third bbs + second bbs + first bbs + 1
              }
    return $ point bbs + third bbs + second bbs + first bbs + 1