N=int(eval(input()))

lasta=0

headb=0

spec=0

cnt=0

for _ in range(N):

    s=str(eval(input()))

    for i in range(len(s)-1):

        if s[i:i+2]=="AB":

            cnt+=1

    if s[0]=="B" and s[-1]=="A":

        spec+=1

    elif s[-1]=="A":

        lasta+=1

    elif s[0]=="B":

        headb+=1

        

if abs(headb-lasta)>=spec:

    print((min(headb,lasta)+spec+cnt))   

elif lasta==0 and headb==0 and spec>0:

    print((spec-1+cnt))

elif lasta==0 and headb==0 and spec==0:

    print(cnt)

else:

    print((spec-abs(headb-lasta)+max(headb,lasta)+cnt))
N=int(eval(input()))

lasta=0

headb=0

spec=0

cnt=0

for _ in range(N):

    s=str(eval(input()))

    cnt+=s.count("AB")

    if s[0]=="B" and s[-1]=="A":

        spec+=1

    elif s[-1]=="A":

        lasta+=1

    elif s[0]=="B":

        headb+=1

        

if abs(headb-lasta)>=spec:

    print((min(headb,lasta)+spec+cnt))   

elif lasta==0 and headb==0 and spec>0:

    print((spec-1+cnt))

elif lasta==0 and headb==0 and spec==0:

    print(cnt)

else:

    print((spec-abs(headb-lasta)+max(headb,lasta)+cnt))
N = int(eval(input()))
lasta = 0
headb = 0
spec = 0
cnt = 0
for _ in range(N):
    s = str(eval(input()))
    for i in range(len(s) - 1):
        if s[i : i + 2] == "AB":
            cnt += 1
    if s[0] == "B" and s[-1] == "A":
        spec += 1
    elif s[-1] == "A":
        lasta += 1
    elif s[0] == "B":
        headb += 1
if abs(headb - lasta) >= spec:
    print((min(headb, lasta) + spec + cnt))
elif lasta == 0 and headb == 0 and spec > 0:
    print((spec - 1 + cnt))
elif lasta == 0 and headb == 0 and spec == 0:
    print(cnt)
else:
    print((spec - abs(headb - lasta) + max(headb, lasta) + cnt))

N = int(eval(input()))
lasta = 0
headb = 0
spec = 0
cnt = 0
for _ in range(N):
    s = str(eval(input()))
    cnt += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        spec += 1
    elif s[-1] == "A":
        lasta += 1
    elif s[0] == "B":
        headb += 1
if abs(headb - lasta) >= spec:
    print((min(headb, lasta) + spec + cnt))
elif lasta == 0 and headb == 0 and spec > 0:
    print((spec - 1 + cnt))
elif lasta == 0 and headb == 0 and spec == 0:
    print(cnt)
else:
    print((spec - abs(headb - lasta) + max(headb, lasta) + cnt))

-    for i in range(len(s) - 1): -        if s[i : i + 2] == "AB": -            cnt += 1 +    cnt += s.count("AB")