s=list(eval(input()))

a=200000

z=0



for i in range(len(s)):

  if s[i]=='A'and a>i:

    a=i

  if s[i]=='Z'and z<i:

    z=i

print((z-a+1))
S=eval(input())

N=len(S)

A=0

Z=0

for i in range(N):

  if S[i]=='A':

    A=i

    #print(A)

    break

    

for i in range(N)[::-1]:

  if S[i]=='Z':

    Z=i

    #print(Z)

    break

    

ans=Z-A+1

print(ans)
s = list(eval(input()))
a = 200000
z = 0
for i in range(len(s)):
    if s[i] == "A" and a > i:
        a = i
    if s[i] == "Z" and z < i:
        z = i
print((z - a + 1))

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

-s = list(eval(input())) -a = 200000 -z = 0 -for i in range(len(s)): -    if s[i] == "A" and a > i: -        a = i -    if s[i] == "Z" and z < i: -        z = i -print((z - a + 1)) +S = eval(input()) +N = len(S) +A = 0 +Z = 0 +for i in range(N): +    if S[i] == "A": +        A = i +        # print(A) +        break +for i in range(N)[::-1]: +    if S[i] == "Z": +        Z = i +        # print(Z) +        break +ans = Z - A + 1 +print(ans)