N=list(eval(input()))

n=len(N)

X=0

for i in range(n):

  if N[i]=="A" :

    X=i

    break

for i in range(n):

  if N[-(i+1)]=="Z" :

    X+=i  

    break

print((n-X))

     
N=list(eval(input()))

n=len(N)

A=N.index("A")

N=N[::-1]

Z=N.index("Z")

print((n-A-Z))
N = list(eval(input()))
n = len(N)
X = 0
for i in range(n):
    if N[i] == "A":
        X = i
        break
for i in range(n):
    if N[-(i + 1)] == "Z":
        X += i
        break
print((n - X))

N = list(eval(input()))
n = len(N)
A = N.index("A")
N = N[::-1]
Z = N.index("Z")
print((n - A - Z))

-X = 0 -for i in range(n): -    if N[i] == "A": -        X = i -        break -for i in range(n): -    if N[-(i + 1)] == "Z": -        X += i -        break -print((n - X)) +A = N.index("A") +N = N[::-1] +Z = N.index("Z") +print((n - A - Z))