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