N = gets.chomp.to_i
texts = []
count = 0
first_b_end_a_count = 0
first_b_end_b_count = 0
first_a_end_a_count = 0
first_a_end_b_count = 0
N.times do |i|
    text = gets.chomp
    count += text.scan("AB").length
    text = text.split("").map(&:to_s)
    text = [text.first,"X",text.last]
    p text
    if text.first == "A"
        if text.last == "A"
            first_a_end_a_count += 1  
        else text.last == "B"
            first_a_end_b_count += 1  
        end
    else text.first == "B"
        if text.last == "A"
            first_b_end_a_count += 1  
        else text.last == "B"
            first_b_end_b_count += 1  
        end
    end
end


# p first_b_end_a_count ##使える
# p first_b_end_b_count ##使える
# p first_a_end_a_count ##使える
# p first_a_end_b_count ##使わない

if first_b_end_a_count >= first_b_end_b_count
    puts count + first_b_end_a_count
else
    if first_b_end_b_count >= first_a_end_a_count
        puts count + first_a_end_a_count
    else
        puts count + first_b_end_b_count
    end
end
