N = int(eval(input()))



count_ab = 0

count_fb = 0

count_ea = 0

count_fbea = 0

for i in range(N):

    s = eval(input())

    count_ab += s.count("AB")

    if s[0] + s[-1] == "BA":

        count_fbea += 1

    elif s[0] == "B":

        count_fb += 1

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

        count_ea += 1



ans = count_ab

if count_fbea > 0:

    ans += count_fbea - 1

    if count_fb > 0:

        count_fb -= 1

        ans += 1

    if count_ea > 0:

        count_ea -= 1

        ans += 1

ans += min(count_fb, count_ea)

print(ans)
import sys

input = sys.stdin.readline



N = int(eval(input()))



count_ab = 0

count_fb = 0

count_ea = 0

count_fbea = 0

for i in range(N):

    s = eval(input())

    count_ab += s.count("AB")

    if s[0] + s[-2] == "BA":

        count_fbea += 1

    elif s[0] == "B":

        count_fb += 1

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

        count_ea += 1



ans = count_ab

if count_fbea > 0:

    ans += count_fbea - 1

    if count_fb > 0:

        count_fb -= 1

        ans += 1

    if count_ea > 0:

        count_ea -= 1

        ans += 1

ans += min(count_fb, count_ea)

print(ans)
N = int(eval(input()))
count_ab = 0
count_fb = 0
count_ea = 0
count_fbea = 0
for i in range(N):
    s = eval(input())
    count_ab += s.count("AB")
    if s[0] + s[-1] == "BA":
        count_fbea += 1
    elif s[0] == "B":
        count_fb += 1
    elif s[-1] == "A":
        count_ea += 1
ans = count_ab
if count_fbea > 0:
    ans += count_fbea - 1
    if count_fb > 0:
        count_fb -= 1
        ans += 1
    if count_ea > 0:
        count_ea -= 1
        ans += 1
ans += min(count_fb, count_ea)
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
count_ab = 0
count_fb = 0
count_ea = 0
count_fbea = 0
for i in range(N):
    s = eval(input())
    count_ab += s.count("AB")
    if s[0] + s[-2] == "BA":
        count_fbea += 1
    elif s[0] == "B":
        count_fb += 1
    elif s[-2] == "A":
        count_ea += 1
ans = count_ab
if count_fbea > 0:
    ans += count_fbea - 1
    if count_fb > 0:
        count_fb -= 1
        ans += 1
    if count_ea > 0:
        count_ea -= 1
        ans += 1
ans += min(count_fb, count_ea)
print(ans)

+import sys + +input = sys.stdin.readline -    if s[0] + s[-1] == "BA": +    if s[0] + s[-2] == "BA": -    elif s[-1] == "A": +    elif s[-2] == "A":