import Control.Monad
type I3 = (Int, Int, Int)
type B2 = (Bool, Bool)

main = do
    n <- readLn
    ss <- replicateM n getLine
    print . f $ map count ss

f :: [(I3, Int)] -> Int
f rs = sum ns + g (nft, ntf, ntt) where
    (cs, ns) = unzip rs
    (nft, ntf, ntt) = foldl1 add3 cs

g :: I3 -> Int
g (nft, ntf, 0) = min nft ntf
g (nft, ntf, ntt) = if ntt > 0
    then if nft > 0
        then if ntf > 0
            then ntt + 1 + min (nft - 1) (ntf - 1)
            else ntt
        else if ntf > 0
            then ntt
            else ntt - 1
    else min nft ntf

add3 :: I3 -> I3 -> I3
add3 (l1,l2,l3) (r1,r2,r3) = (l1+r1,l2+r2,l3+r3)

count :: String -> (I3, Int)
count (s0:s) = (count' (na, nb), n) where
    na = last s == 'A'
    nb = s0 == 'B'
    n = length [() | (c1, c2) <- zip (s0:s) s, c1 == 'A' && c2 == 'B']
    count' (False,False) = (0,0,0)
    count' (False, True) = (1,0,0)
    count' ( True,False) = (0,1,0)
    count' ( True, True) = (0,0,1)
