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=max (min(sa-1)sb) (min(sb-1)sa)
     pa=(\x->if x>=1 then 1 else 0)(sum$map(\x->if take 2 x=="AB" then 1 else 0)ss)
     pb=(\x->if x>=1 then 1 else 0)(sum$map(\x->if last x=='B'&&last(init x)=='A' then 1 else 0)ss)
 print$sr+sp+pa+pb