import Data.List

main = interact $ unlines . map (show . step_aerobics) . read' . lines
 where
  read' ("0":_) = []
  read' (_:steps:xs) = words steps : read' xs

step_aerobics steps = min left right
 where
  left  = length $ group $ filter (\(c:_) -> c == 'l') steps
  right = length $ group $ filter (\(c:_) -> c == 'r') steps