s = eval(input())



ind_A = 0

while s[ind_A] != 'A':

    ind_A += 1

ind_Z = len(s)

while s[ind_Z - 1] != 'Z':

    ind_Z -= 1



print((ind_Z - ind_A))
s = eval(input())



a = s.index('A')

z = len(s) - s[-1::-1].index('Z')

print((z - a))
s = eval(input())
ind_A = 0
while s[ind_A] != "A":
    ind_A += 1
ind_Z = len(s)
while s[ind_Z - 1] != "Z":
    ind_Z -= 1
print((ind_Z - ind_A))

s = eval(input())
a = s.index("A")
z = len(s) - s[-1::-1].index("Z")
print((z - a))

-ind_A = 0 -while s[ind_A] != "A": -    ind_A += 1 -ind_Z = len(s) -while s[ind_Z - 1] != "Z": -    ind_Z -= 1 -print((ind_Z - ind_A)) +a = s.index("A") +z = len(s) - s[-1::-1].index("Z") +print((z - a))