output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      s_1
      \vdots
      s_N
attempt: N = int(input())
  A = []
  for i in range(N):
      A.append(input())
  X = 0
  W = 0
  for i in A:
      i = "".join(i)
      Q = i.count("AB")
      if Q == 1:
          W += 1
  
  # B="".join(A)
  # print(B)
  # Y=B.count("AB")
  
  # print(Y)
  Z1 = 0
  
  
  Z3 = 0
  z = 0
  for i in A:
  
      # print(i[-1])
      i = "".join(i)
      C = A.index(i)
      if C != 0:
          z += 1
          C = C - z
      D = A[C]
      # print(D)#取り出したやつ
  
      A.pop(C)
      # print(A)
  
      # print(C)
      # print(A)
      Z1 = 0
      if i[-1] == "A":
          for j in A:
  
              if j[0] == "B":
                  Z1 += 1
          #        print(Z1)
      A.append(D)
      # print(A)
      # print(A)
      if Z3 < Z1:
          Z3 = Z1
  
  
  W += Z3
  print(W)
  
problem_description: Statement
  
  Snuke has N strings. The i-th string is s_i.
  
  Let us concatenate these strings into one string after arranging them in some
  order. Find the maximum possible number of occurrences of `AB` in the
  resulting string.
samples: [{"input": "3\n    ABCA\n    XBAZ\n    BAD", "output": "2\n    \n\nFor example, if we concatenate `ABCA`, `BAD` and `XBAZ` in this order, the\nresulting string `ABCABADXBAZ` has two occurrences of `AB`.\n\n* * *"}, {"input": "9\n    BEWPVCRWH\n    ZZNQYIJX\n    BAVREA\n    PA\n    HJMYITEOX\n    BCJHMRMNK\n    BP\n    QVFABZ\n    PRGKSPUNA", "output": "4\n    \n\n* * *"}, {"input": "7\n    RABYBBE\n    JOZ\n    BMHQUVA\n    BPA\n    ISU\n    MCMABAOBHZ\n    SZMEHMA", "output": "4"}]