let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let ss = Array.init n @@ fun _ -> read_line ()

let count_ab str =
  let t = Str.global_replace (Str.regexp "AB") "." str in
  (String.length str) - (String.length t)

let f str = (count_ab str, str.[0] = 'B', str.[String.length str - 1] = 'A')

let () =
  let ss = Array.map f ss in
  let ab_count = Array.fold_left (fun sum (a, _, _) -> sum + a) 0 ss in
  let both, only_a, only_b = ref 0, ref 0, ref 0 in
  Array.iter (fun (_, x, y) ->
    if x && y then both := !both + 1
    else if x then only_a := !only_a + 1
    else if y then only_b := !only_b + 1
  ) ss;
  Printf.printf "%d\n" @@ ab_count +
    if !both = 0 then (min !only_a !only_b)
    else if !only_a = 0 && !only_b = 0 then !both - 1
    else !both + (min !only_a !only_b)
