n = gets.to_i
hs = Hash.new(0)
n.times do
  s = gets.chomp
  pr = s[0]
  su = s[-1]
  hs["AB"] += s.scan("AB").size
  if pr + su == "BA"
    hs["BA"] += 1
  elsif su == "A"
    hs["_A"] += 1
  elsif pr == "B"
    hs["B_"] += 1
  end
end

if hs["_A"] > 0 && hs["B_"] > 0
  cnt = [hs["_A"], hs["B_"]].min
  hs["_A"] -= cnt
  hs["B_"] -= cnt
  hs["AB"] += cnt
elsif hs["_A"] > 0 && hs["BA"] > 0
  cnt = [hs["_A"], hs["BA"]].min
  hs["_A"] -= cnt
  hs["BA"] -= cnt
  hs["AB"] += cnt
elsif hs["B_"] > 0 && hs["BA"] > 0
  cnt = [hs["_A"], hs["BA"]].min
  hs["BA"] -= cnt
  hs["B_"] -= cnt
  hs["AB"] += cnt
elsif hs["BA"] > 1
  hs["AB"] += hs["BA"] - 1
  hs["BA"] = 0
else
  puts hs["AB"]
  exit
end
puts hs["AB"] + (hs["BA"] + [hs["B_"], hs["A_"]].min)