import Control.Monad
import Data.List
f n s
 |null s=n
 |null (init s)=n
 |s!!0=='A'&&s!!1=='B'=f(n+1)(drop 1 s)
 |otherwise=f(n)(drop 1 s)
main=do
 n<-readLn :: IO Int
 ss<-replicateM n getLine
 let sr=sum$map(f 0)ss
     sa=sum$map(\x->if head x=='B' &&last x/='A'then 1 else 0)ss
     sb=sum$map(\x->if last x=='A' &&head x/='B'then 1 else 0)ss
     ab=sum$map(\x->if head x=='B' &&last x=='A'then 1 else 0)ss
     sq=if ab==0 then min sa sb else if sa==0&&sb==0 then ab-1 else if sa==0||sb==0 then ab else ab+1+(min (sa-1) (sb-1))
 print$sr+sq