using System;
using System.Collections;
using System.Text;
class Program {
    static void Main(string[] args) {
#if LOCAL_ENVIRONMENT
        var stdin = new System.IO.StreamReader("stdin.txt");
        System.Console.SetIn(stdin);
#endif
        SimpleScanner sc = new SimpleScanner();
        int N = sc.NextInt();
        string[] S = sc.NextStringArray(N);
        long ans = 0, startB = 0, endA = 0, startEnd = 0;
        for (var n = 0; n < N; n++) {
            for (var m = 0; m < S[n].Length - 1; m++) {
                if (S[n][m] == 'A' && S[n][m+1] == 'B') ans++;
            }
            if (S[n][0] == 'B' && S[n][S[n].Length - 1] == 'A') startEnd++;
            else {
                if (S[n][0] == 'B') startB++;
                if (S[n][S[n].Length - 1] == 'A') endA++;
            }
        }
#if LOCAL_ENVIRONMENT
Console.Error.WriteLine("a: {0}, b: {1}, ab: {2}, ans: {3}", endA, startB, startEnd, ans);
#endif
        long a_b = Math.Min(startB, endA);
        long ab = 0;
        if (startEnd > 0) {
            if (startB + endA > 0) ab = startEnd;
            else ab = startEnd - 1;
        }
        ans += a_b + ab;
        Console.WriteLine(ans);

    } //Main

    public class SimpleScanner {
        private int cnt;
        private string[] items;
        public SimpleScanner() {
            this.cnt = 0;
            var sb = new StringBuilder();
            var s = Console.ReadLine();
            while (s != null) {
                sb.Append(s + " ");
                s = Console.ReadLine();
            }
            this.items = sb.ToString().Split(' ');
#if LOCAL_ENVIRONMENT
    Console.Error.WriteLine("SimpleScanner.items: {0}" , this.items.ToStringA());
#endif
        }
        public void SetCnt(int n) { this.cnt = n; }
        public int NextInt() {
            return int.Parse(this.items[this.cnt++]);
        }
        public long NextLong() {
            return long.Parse(this.items[this.cnt++]);
        }
        public string NextString() {
            return this.items[this.cnt++];
        }
        public int[] NextIntArray(int n) {
            if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること！");
            var result = new int[n];
            for (var i = 0; i < n; i++) result[i] = this.NextInt();
#if LOCAL_ENVIRONMENT
            Console.Error.WriteLine("{0}", result.ToStringA());
#endif
            return result;
        }
        public long[] NextLongArray(int n) {
            if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること！");
            var result = new long[n];
            for (var i = 0; i < n; i++) result[i] = this.NextLong();
#if LOCAL_ENVIRONMENT
            Console.Error.WriteLine("{0}", result.ToStringA());
#endif
            return result;
        }
        public string[] NextStringArray(int n) {
            if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること！");
            var result = new string[n];
            for (var i = 0; i < n; i++) result[i] = this.NextString();
#if LOCAL_ENVIRONMENT
            Console.Error.WriteLine("{0}", result.ToStringA());
#endif
            return result;
        }
        public int[][] NextInt2Col(int n) {
            const int M = 2;
            if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること！");
            int[][] result = new int[M][] {
                new int[n],
                new int[n],
            };
            for (var i = 0; i < n; i++) {
                result[0][i] = this.NextInt();
                result[1][i] = this.NextInt();
            }
#if LOCAL_ENVIRONMENT
            Console.Error.WriteLine("NextInt2Col: [");
            for (var i = 0; i < M; i++)
                Console.Error.WriteLine("  {0},", result[i].ToStringA());
            Console.Error.WriteLine("]");
#endif
            return result;
        }
    }
}


Measured memory_bytes: 13664