main :: IO ()
main = do
  ls <- getContents
  let ls' = remake $ lines ls
      ansl = map point' ls'
      ansl' = (init ansl) ++ [lastPoint (last ansl)]
      ansl'' = map format ansl'
  mapM_ putStrLn ansl''
remake :: [String] -> [String]
remake [] = []
remake ("0":[]) = []
remake (x:"0":[]) = [(tail x)]
remake (x:y:r) = ((tail x) ++ [head y]):(remake (y:r))

point :: String -> (Int,Int) -> (Int,Int)
point [] (a,b) = (a,b)
point ('A':r) (a,b) = point r (a+1,b)
point ('B':r) (a,b) = point r (a,b+1)

point' :: String -> (Int,Int)
point' s = point s (0,0)

lastPoint :: (Int,Int) -> (Int,Int)
lastPoint (a,b)
  | a < b = (a,b+1)
  | otherwise = (a+1,b)

format :: (Int,Int) -> String
format (a,b) = (show a) ++ " " ++ (show b)