N = gets.to_i
s_list = N.times.map { gets.chomp.chars }
count = s_list.map do |s|
  c = 0
  prev = nil
  s.each do |ch|
    if prev == 'A' && ch == 'B'
      c += 1
    end
    prev = ch
  end
  c
end.reduce(0) { |acc, n| acc + n }
a_count = s_list.count do |s|
  s[-1] == 'A'
end
b_count = s_list.count do |s|
  s[0] == 'B'
end
a_and_b_count = s_list.count do |s|
  s[0] == 'B' && s[-1] == 'A'
end
a_count -= a_and_b_count
b_count -= a_and_b_count
rest_count = (a_count != b_count) ? a_and_b_count : [a_and_b_count - 1, 0].max
ans = [a_count, b_count].min + rest_count + count
puts ans
