n=gets.to_i
ba,bs,sa,result=0,0,0,0
n.times do 
  s=gets.chomp
(s.size-1).times do |i|
  if s[i]=="A" && s[i+1]=="B"
    result+=1
  end
end
ba+=1 if s[0]=="B" && s[-1]=="A"
bs+=1 if s[0]=="B" && s[-1]!="A"
sa+=1 if s[0]!="B" && s[-1]=="A"
end
if bs==0&&sa==0
result+=(ba-1)
elsif bs>sa
  result+=ba+sa
else
  result+=ba+bs
end
puts result