#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;
}
*/

Measured memory_bytes: 1152