let abs s =
  snd @@ Array.fold_left (fun (c, abs) c' ->
    (c', abs + if c = 'A' && c' = 'B' then 1 else 0)) ('_', 0) @@
  Array.init (String.length s) (String.get s)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let (a, a', b, b', ab, ba) =
    Array.fold_left (fun (a, a', b, b', ab, ba) s ->
      match s.[0], s.[String.length s - 1] with
      | 'B', 'A' -> (a, a', b, b', ab, ba + 1)
      | 'A', 'B' -> (a, a', b, b', ab + 1, ba)
      | _, 'B' -> (a, a', b, b' + 1, ab, ba)
      | 'B', _ -> (a, a', b + 1, b', ab, ba)
      | _, 'A' -> (a, a' + 1, b, b', ab, ba)
      | 'A', _ -> (a + 1, a', b, b', ab, ba)
      | _, _ ->  (a, a', b, b', ab, ba)) (0, 0, 0, 0, 0, 0) ss in
  Printf.printf "%d\n" @@
  max 0 (ba - 1) + min (a' + min 1 ba) (b + min 1 ba) +
  max 0 (ab - 1) + min (a + min 1 ab) (b' + min 1 ab) +
  Array.fold_left (fun a s -> a + abs s) 0 ss