S=eval(input())



for i in range(len(S)):

  if S[i]=='A':

    S=S[i:]

    break



for i in range(len(S)-1,0,-1):

  if S[i]=='Z':

    S=S[:i+1]

    break

    

print((len(S)))
S=eval(input())

S=S[S.find('A'):S.rfind('Z')+1]

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

S = eval(input())
S = S[S.find("A") : S.rfind("Z") + 1]
print((len(S)))

-for i in range(len(S)): -    if S[i] == "A": -        S = S[i:] -        break -for i in range(len(S) - 1, 0, -1): -    if S[i] == "Z": -        S = S[: i + 1] -        break +S = S[S.find("A") : S.rfind("Z") + 1]