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
ga x=if take 2 x=="AB" then True else False
gb x=if last x=='B'&&last(init x)=='A' then True else False
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)
     sq=if sb<=0 then 0 else sp
     pa=sum$map(\x->if ga x then 1 else 0)ss
     pb=sum$map(\x->if gb x then 1 else 0)ss
     pq=sum$map(\x->if ga x&&gb x then 1 else 0)ss
     pp=if pa==1&&pb==1&&pq==1 then 1 else (\x->if x>=1 then 1 else 0)pa+(\x->if x>=1 then 1 else 0)pb
     
 print$sr+sq+pp