import Control.Monad

concat_bonus::Int->Int->Int->Int
concat_bonus left_b right_a b_a = if b_a == 0 then min left_b  right_a
                                              else (b_a - 1) + case (left_b >= 1, right_a >= 1) of
                                                                (True,True) -> 1 + (min left_b right_a)
                                                                (True,False)-> 1
                                                                (False,True)-> 1
                                                                (False,False)->0
indep_appear::String->Int
indep_appear str = length (((filter (\ (c,d)-> c=='A' && d == 'B'))) (zip str (tail str)))

counter::(Int,Int,Int)->[String]->(Int,Int,Int)
counter (lb,ra,ba) []         = (lb,ra,ba)
counter (lb,ra,ba) (str:strs) = case (head str,last str) of
                                ('B','A') -> counter (lb,ra,ba+1) strs
                                ('B',_  ) -> counter (lb+1,ra,ba) strs
                                (_  ,'A') -> counter (lb,ra+1,ba) strs
                                otherwise -> counter (lb,ra,ba) strs

solver::[String]->Int
solver strs = let n = sum (map indep_appear strs) in
              let (lb,ra,ba) = counter (0,0,0) strs in
              n + (concat_bonus lb ra ba)

main::IO()
main=do
  n<-return.read=<<getLine
  strs<-forM [1..n] (\_-> getLine)
  print (solver strs)
