// 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.5926921549140247x):
#include<stdio.h>

#include<iostream>

#include<math.h> 

#include<string.h>

#include<algorithm>

using namespace std;

typedef long long ll;

ll n;

int len[10000+100];

char s[10000+100][100];

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>s[i];

		len[i]=strlen(s[i]);

	}

	ll a=0,b=0,sum=0;

	int ss=0;

	for(int i=1;i<=n;i++)

	{

		if(s[i][0]=='B'&&s[i][len[i]-1]=='A')

		{

			ss++;

		}

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

		{

			b++;

		}

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

		{

			a++;

		}

		for(int j=0;j<len[i]-1;j++)

		{

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

		}

	}

//	printf("%d %d %d %d\n",ss,sum,a,b);

	if(ss==0)

	{

		sum=sum+min(a,b);

	}

	else

	{

		if(b>0&&a>0)

		{

			sum=sum+ss+1+min(a-1,b-1);

		}

		else if((a>0&&b==0)||b>0&&a==0)

		{

			sum=sum+ss;

		}

		else if(a==0&&b==0)

		{

			sum=sum+ss-1;

		}

	}

	printf("%lld\n",sum);

	return 0;

}