n = gets.to_i

res = 0
top = 0
bot = 0
mid = 0

def howmany_ab(s)
    before = ""
    res = 0
    s.chars do |c|
        res += 1 if before == 'A' && c == 'B'
        before = c
    end
    return res
end


n.times do
    inp =  gets.chomp
    ab = inp[0] + inp[-1]
    res += howmany_ab(inp)
    top += 1 if ab[0] != "B" && ab[1] == "A"
    mid += 1 if ab[0] == "B" && ab[1] == "A"
    bot += 1 if ab[0] == "B" && ab[1] != "A"
end


rest_top = top - mid
rest_bot = bot - mid

res += [mid, top].min
res += [mid, bot].min
rest_mid = mid - [top, bot].max
res += [rest_top, rest_bot].min if rest_top > 0 && rest_bot > 0

puts res

