from sys import stdin

N=int(stdin.readline().rstrip())

 

data=[]

ans=0

A=0

B=0

ab=0

for i in range(N):

    S=eval(input())

    ans+=S.count("AB")

    if S[0] == "B":

        B+=1

    if S[-1] == "A":

        A+=1

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

        ab+=1

if ab == 0:

    print((ans+min(A,B)))

    

elif A == B == ab:

    print((ans+ab-1))



else:

    print((ans+min(A,B)))
from sys import stdin

N = int(stdin.readline().rstrip())

ans = 0

c1 = 0

c2 = 0

c3 = 0

for _ in range(N):

    s = (stdin.readline().rstrip())

    ans += s.count("AB")

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

        c1 += 1

    elif s[0] == "B":

        c2 += 1

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

        c3 += 1

if c1 == 0:

    ans += min(c2,c3)

else:

    if c2 + c3 == 0:

        ans += (c1-1)

    else:

        ans += (c1 + min(c2,c3))

print(ans)
from sys import stdin

N = int(stdin.readline().rstrip())
data = []
ans = 0
A = 0
B = 0
ab = 0
for i in range(N):
    S = eval(input())
    ans += S.count("AB")
    if S[0] == "B":
        B += 1
    if S[-1] == "A":
        A += 1
    if S[-1] == "A" and S[0] == "B":
        ab += 1
if ab == 0:
    print((ans + min(A, B)))
elif A == B == ab:
    print((ans + ab - 1))
else:
    print((ans + min(A, B)))

from sys import stdin

N = int(stdin.readline().rstrip())
ans = 0
c1 = 0
c2 = 0
c3 = 0
for _ in range(N):
    s = stdin.readline().rstrip()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        c1 += 1
    elif s[0] == "B":
        c2 += 1
    elif s[-1] == "A":
        c3 += 1
if c1 == 0:
    ans += min(c2, c3)
else:
    if c2 + c3 == 0:
        ans += c1 - 1
    else:
        ans += c1 + min(c2, c3)
print(ans)

-data = [] -A = 0 -B = 0 -ab = 0 -for i in range(N): -    S = eval(input()) -    ans += S.count("AB") -    if S[0] == "B": -        B += 1 -    if S[-1] == "A": -        A += 1 -    if S[-1] == "A" and S[0] == "B": -        ab += 1 -if ab == 0: -    print((ans + min(A, B))) -elif A == B == ab: -    print((ans + ab - 1)) +c1 = 0 +c2 = 0 +c3 = 0 +for _ in range(N): +    s = stdin.readline().rstrip() +    ans += s.count("AB") +    if s[0] == "B" and s[-1] == "A": +        c1 += 1 +    elif s[0] == "B": +        c2 += 1 +    elif s[-1] == "A": +        c3 += 1 +if c1 == 0: +    ans += min(c2, c3) -    print((ans + min(A, B))) +    if c2 + c3 == 0: +        ans += c1 - 1 +    else: +        ans += c1 + min(c2, c3) +print(ans)