import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	string[] ss;
	foreach(i; 0 .. n) ss ~= readln.chomp;
	
	int abcount, acount, bcount, bacount;
	foreach(s; ss){
		if(s[0] == 'B') bcount += 1;
		if(s[$ - 1] == 'A') acount += 1;
		if(s[0] == 'B' && s[$ - 1] == 'A') bacount += 1;
		for(int i = 0; i < s.length - 1; i ++) if(s[i] == 'A' && s[i + 1] == 'B') abcount += 1;
	}
	print!1("ab:", abcount, " a:", acount, " b:", bcount, " ba:", bacount);
	
	int ans = abcount;
	if(acount < bcount) ans += acount;
	else if(acount > bcount) ans += bcount;
	else if(acount > 0 && acount == bacount) ans += acount - 1;
	else ans += acount;
	
	ans.writeln;
}

/*
①元々文字列の内部にあるAB
②Aで終わりBで始まる

②は、Aで終わる個数とBで始まる個数の少ない方
ただしAで終わるやつの全てがBで始まる場合は場合は1つ減らす


*/
