"use strict";
function main(input) {
  const args = input.split("\n");

  const N = parseInt(args[0]);

  const p = /(AB)+/g;

  let testStr;
  let testStrLen;
  let countAB = 0;

  let BA = 0;
  let firstB = 0;
  let lastA = 0;

  for(let i = 0; i < N; i++) {
      testStr = args[i + 1];
      testStrLen = testStr.length;
      while(p.exec(testStr)) {
          countAB ++;
      }
      if (testStr.charAt(0) == "B") {
        if (testStr.charAt(testStrLen - 1) == "A") {
          BA++;
        } else {
          firstB++;
        }
      } else if (testStr.charAt(testStrLen - 1) == "A") {
        lastA++;
      }
  }

  if(BA + lastA < BA + firstB) {
      countAB += BA + lastA;
  } else {
      countAB += BA + firstB;
  }

  console.log(countAB);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

