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 = begin
  c = 0
  while a_and_b_count > 0
    if a_count > 0 && b_count > 0
      c += 2
      a_count -= 1
      b_count -= 1
      a_and_b_count -= 1
    elsif a_count > 0
      c += 1
      a_count -= 1
      b_count += 1
      a_and_b_count -= 1
    elsif b_count > 0
      c += 1
      a_count += 1
      b_count -= 1
      a_and_b_count -= 1
    else
      c += a_and_b_count - 1
      a_and_b_count = 0
    end
  end
  c + [a_count, b_count].min
end
ans = count + rest_count
puts ans
