def main():

    N = int(eval(input()))

    ab_cnt = 0

    b_cnt = 0

    a_cnt = 0

    ans = 0

    for _ in range(N):

        S = eval(input())

        ans += S.count("AB")

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

            ab_cnt += 1

        elif S[0] == "B":

            b_cnt += 1

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

            a_cnt += 1

    if ab_cnt > 1:

        ans += max(ab_cnt - 1, 0)

        ab_cnt = 1

    if a_cnt <= b_cnt:

        ans += a_cnt

        a_cnt = 0

        b_cnt -= a_cnt

    elif b_cnt < a_cnt:

        ans += b_cnt

        b_cnt = 0

        a_cnt -= b_cnt

    if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):

        ans += 1

    print(ans)





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    A = [eval(input()) for i in range(N)]

    ans = 0

    ba = 0

    b = 0

    a = 0

    for s in A:

        ans += s.count("AB")

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

            ba += 1

        elif s[0] == "B":

            b += 1

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

            a += 1

    ans += (ba - 1 if ba > 1 else 0)

    if ba > 0 and a > 0 and b > 0:

        b += 1

        a += 1

        ans += min(a, b)

    elif ba > 0 and a == 0 and b == 0:

        pass

    elif ba > 0 and a > 0:

        ans += 1

    elif ba > 0 and b > 0:

        ans += 1

    elif ba == 0:

        ans += min(a, b)

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    ab_cnt = 0
    b_cnt = 0
    a_cnt = 0
    ans = 0
    for _ in range(N):
        S = eval(input())
        ans += S.count("AB")
        if S[0] == "B" and S[-1] == "A":
            ab_cnt += 1
        elif S[0] == "B":
            b_cnt += 1
        elif S[-1] == "A":
            a_cnt += 1
    if ab_cnt > 1:
        ans += max(ab_cnt - 1, 0)
        ab_cnt = 1
    if a_cnt <= b_cnt:
        ans += a_cnt
        a_cnt = 0
        b_cnt -= a_cnt
    elif b_cnt < a_cnt:
        ans += b_cnt
        b_cnt = 0
        a_cnt -= b_cnt
    if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A = [eval(input()) for i in range(N)]
    ans = 0
    ba = 0
    b = 0
    a = 0
    for s in A:
        ans += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            ba += 1
        elif s[0] == "B":
            b += 1
        elif s[-1] == "A":
            a += 1
    ans += ba - 1 if ba > 1 else 0
    if ba > 0 and a > 0 and b > 0:
        b += 1
        a += 1
        ans += min(a, b)
    elif ba > 0 and a == 0 and b == 0:
        pass
    elif ba > 0 and a > 0:
        ans += 1
    elif ba > 0 and b > 0:
        ans += 1
    elif ba == 0:
        ans += min(a, b)
    print(ans)


if __name__ == "__main__":
    main()

-    ab_cnt = 0 -    b_cnt = 0 -    a_cnt = 0 +    A = [eval(input()) for i in range(N)] -    for _ in range(N): -        S = eval(input()) -        ans += S.count("AB") -        if S[0] == "B" and S[-1] == "A": -            ab_cnt += 1 -        elif S[0] == "B": -            b_cnt += 1 -        elif S[-1] == "A": -            a_cnt += 1 -    if ab_cnt > 1: -        ans += max(ab_cnt - 1, 0) -        ab_cnt = 1 -    if a_cnt <= b_cnt: -        ans += a_cnt -        a_cnt = 0 -        b_cnt -= a_cnt -    elif b_cnt < a_cnt: -        ans += b_cnt -        b_cnt = 0 -        a_cnt -= b_cnt -    if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0): +    ba = 0 +    b = 0 +    a = 0 +    for s in A: +        ans += s.count("AB") +        if s[0] == "B" and s[-1] == "A": +            ba += 1 +        elif s[0] == "B": +            b += 1 +        elif s[-1] == "A": +            a += 1 +    ans += ba - 1 if ba > 1 else 0 +    if ba > 0 and a > 0 and b > 0: +        b += 1 +        a += 1 +        ans += min(a, b) +    elif ba > 0 and a == 0 and b == 0: +        pass +    elif ba > 0 and a > 0: +    elif ba > 0 and b > 0: +        ans += 1 +    elif ba == 0: +        ans += min(a, b)