import Data.List
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- replicateM n getLine
  let baseab = length . filter (isInfixOf "AB") $ ss
      lasta  = length . filter (not . isPrefixOf "B") . filter (isSuffixOf "A") $ ss
      firstb = length . filter (not . isSuffixOf "A") . filter (isPrefixOf "B") $ ss
      bothab = length . filter (isSuffixOf "A")       . filter (isPrefixOf "B") $ ss
  print $ baseab + solve lasta firstb bothab
  -- print $ baseab + if lasta == 0 && firstb == 0 && bothab > 0
  --                  then bothab - 1
  --                  else bothab + min lasta firstb

solve :: Int -> Int -> Int -> Int
solve x y z
  | z == 0 = min x y
  | z > 0 && x + y > 0 = z + min x y
  | z > 0 && x + y == 0 = z - 1
