import Data.List

main = interact $ unlines . map (show . step_aerobics) . unfoldr read' . lines
 where read' (x:xs) = if x=="0" then Nothing else Just (words (head xs), tail xs)

step_aerobics = fst . foldl' (flip step) (0,[])
 where
  step "ru" (n,("lu":acc)) = (n+1,acc)
  step "lu" (n,("ru":acc)) = (n+1,acc)
  step "rd" (n,("ld":acc)) = (n+1,acc)
  step "ld" (n,("rd":acc)) = (n+1,acc)
  step "ld" (n,("lu":acc)) = (n,acc)
  step "rd" (n,("ru":acc)) = (n,acc)
  step "lu" (n,("ld":acc)) = (n,acc)
  step "ru" (n,("rd":acc)) = (n,acc)
  step s (n,acc) = (n,s:acc)