N = gets.to_i

end_with_a = 0
start_with_b = 0
intersection = 0
ans = 0

N.times do
 s = gets.chomp
 if s[0] == "B" && s[s.length-1] != "A"
   start_with_b += 1
 end

 if s[s.length-1] == "A" && s[0] != "B"
   end_with_a += 1
 end

 if s[0] == "B" && s[s.length-1] == "A"
   intersection += 1
 end


 0.upto(s.length-2) do |i|
   if s[i] == "A" && s[i+1] == "B"
     ans += 1
   end
 end
end

ans += intersection
ans +=
  if start_with_b > end_with_a
    end_with_a
  else
    start_with_b
  end

# puts start_with_b
# puts end_with_a
# puts intersection
puts ans
