// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

string s[10005];

long long int a[10005][3] = {0};	//标记数组

int main()

{

	long long int n;

	while(cin >> n)

	{

		string str;

		long long int flag = 0, q = 0, count = 0;

		memset(a, 0, sizeof(a));

		for(long long int i = 0; i < n; i++)

		{

			cin >> s[i];

			if(s[i][0] == 'B') a[i][0]++;					//如果首字母是B

			if(s[i][s[i].size() - 1] == 'A') a[i][1]++;		//如果尾字母是A

		}

		for(long long int i = 0; i < n; i++)

			if(a[i][0] == 0 && a[i][1] != 0)    //如果首字母不是B，尾字母是A

			{

				flag = 1;

				str += s[i];

				a[i][2] = -1;

				break;

			}

		if(flag == 1)//如果首字母不是B，尾字母是A

		{

			for(long long int i = 0; i < n;i++)

				if(a[i][2] == -1) continue;

				else

				{

					if(a[i][0] != 0 && a[i][1] != 0)

					{

						str += s[i];

						a[i][2] = -1;

					}

				}

			for(long long int i = 0; i < n; i++)

				if(a[i][2] == -1) continue;

				else

				{

					if(a[i][0] != 0)

					{

						str += s[i];

						a[i][2] = -1;

						break;

					}

				}

			for(long long int i = 0; i < n; i++)

			{

				if(a[i][2] == -1) continue;

				else

				{

					if(q % 2 == 0)

					{

						if(a[i][1] != 0)

						{

							str += s[i];

							a[i][2] = -1;

							i = -1;

							q++;

						}

					}

					else

					{

						if(a[i][0] != 0)

						{

							str += s[i];

							a[i][2] = -1;

							i = -1;

							q++;

						}

					}

				}

			}

			for(long long int i = 0; i < n; i++)

				if(a[i][2] != -1)

				{

					str += s[i];

					a[i][2] = -1;

				}

		}

		if(flag == 0)

		{

			for(long long int i = 0; i < n; i++)

				if(a[i][1] != 0 && a[i][2] != -1)

				{

					str += s[i];

					a[i][2] = -1;

					break;

				}

			for(long long int i = 0; i < n; i++)

				if(a[i][2] == -1)continue;

				else

				{

					if(a[i][0] != 0 && a[i][1] != 0)

					{

						str += s[i];

						a[i][2] = -1;

					}

				}

			for(long long int i = 0; i < n; i++)

				if(a[i][2] == -1) continue;

				else

				{

					if(a[i][0] != 0)

					{

						str += s[i];

						a[i][2] = -1;

					}

				}

			for(long long int i = 0; i < n; i++)

				if(a[i][2] != -1)

				{

					str += s[i];

					a[i][2] = -1;

				}

		}

		for(long long int i = 0; i < str.size() - 1; i++)

			if(str[i] == 'A' && str[i + 1] == 'B') count++;

		cout << count << endl;

	}

	return 0;

}



/*

#include<iostream>

#include<cstring>

using namespace std;

string s[10005];

long long int flag[10005] = {0};

long long int min(long long int a, long long int b)

{

	if(a < b) return a;

	return b;

}

long long int a[10005][3]={0};

int main()

{

	long long int n;

	while(cin >> n)

	{

		long long int num_1 = 0, num_2 = 0, num_3 = 0, num_4 = 0;

		memset(s, 0, sizeof(s));

		memset(flag, 0, sizeof(flag));

		long long int count = 0;

		for(long long int i = 0; i < n; i++)

		{

			cin >> s[i];

			if(s[i][0]=='B') a[i][0]++;					//如果首字母是B

			if(s[i][s[i].size()-1]=='A') a[i][1]++;		//如果尾字母是A

			long long int len = s[i].length();

			for(long long int j = 1; j < len; j++)

				if(s[i][j - 1] == 'A' && s[i][j] == 'B') count++;

			if(s[i][0] == 'B' && s[i][len - 1] == 'A'){flag[i] = 1; num_1++;} //首字母B，尾字母A

			if(s[i][0] == 'B' && s[i][len - 1] != 'A'){flag[i] = 2; num_2++;} //首字母B，尾字母非A

			if(s[i][0] != 'B' && s[i][len - 1] == 'A'){flag[i] = 3; num_3++;} //首字母非B，尾字母A

			if(s[i][0] != 'B' && s[i][len - 1] != 'A'){flag[i] = 4; num_4++;} //首字母非B，尾字母非A

		}

		long long int d;

		if(num_2 > num_3) d = num_2 - num_3;

		else if(num_2 <= num_3) d = num_3 - num_2;

		count += min(num_3, num_2);

		count += min(d, num_1);

		cout << count << endl;

	}

	return 0;

}

*/

// Faster C++ solution for the same problem (measured speedup: 1.5665241888974024x):
#include <bits/stdc++.h>



using namespace std;



const int maxN = 10000;

const int maxs = 10;



int N;

char s[maxN][maxs + 1];

int c[4];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(nullptr);

	cout.tie(nullptr);



	cin >> N;

	for (int i = 0; i < N; i++)

		cin >> s[i];



	int ans = 0;

	for (int i = 0; i < N; i++) {

		int l = strlen(s[i]);

		for (int j = 0; j + 2 <= l; j++) {

			if (s[i][j] == 'A' && s[i][j + 1] == 'B')

				ans++;

		}

		int x = 0;

		if (s[i][0] == 'B')

			x |= 1;

		if (s[i][l - 1] == 'A')

			x |= 2;

		c[x]++;

	}

	

	int z = max(0, min(c[1], c[2]) - 1);

	ans += z;

	c[1] -= z;

	c[2] -= z;



	c[1] = min(c[1], 1);

	c[2] = min(c[2], 1);



	ans += max(0, accumulate(c + 1, c + 4, -1));



	cout << ans << '\n';



	return 0;

}