N = readline.to_i
last_a = 0
first_b = 0
la_fb = 0
count = 0
N.times do
  s = readline.chomp
  first_b += 1 if s[0] == 'B'
  last_a += 1 if s[-1] == 'A'
  la_fb += 1 if s[-1] == 'A' and s[0] == 'B'
  s.each_char.with_index do |c,i|
    count += 1 if c == 'A' and s[i+1] == 'B'
  end
end

n = [last_a,first_b].min
n -= 1 if last_a == la_fb and first_b == la_fb
n = 0 if n < 0
# p count, first_b, last_a, n
puts count + n

