n = gets.to_i
ss = []
# ab_count = ss.count { |s| s.include? 'AB' }
# la_count = ss.count { |s| s[-1] == 'A' }
# fb_count = ss.count { |s| s[0] == 'B' }
ab_count = 0
la_count = 0
fb_count = 0
n.times do
  s = gets.chomp
  (0..s.size-2).each do |i|
    if s[i..i+1] == 'AB'
      ab_count += 1
    end
  end
  la_count += 1 if s[-1] == 'A'
  fb_count += 1 if s[0] == 'B'
end
# ab_count = ss.count { |s| s.include? 'AB' }
# la_count = ss.count { |s| s[-1] == 'A' }
# fb_count = ss.count { |s| s[0] == 'B' }
# puts ab_count
# puts la_count
# puts fb_count
puts ab_count + [la_count, fb_count].min