s = list(eval(input()))



a_index = 0

z_index = 0

max_z_index = 0



for i in range(len(s)):

    if s[i] == "A":

        a_index = i

        break



for j in range(len(s)):

    if j <= a_index:

        continue

    else:

        if s[j] == "Z":

            z_index = j

            max_z_index = max(max_z_index, z_index)



print((max_z_index - a_index + 1))
s=eval(input())

a=0

z=0

for i in range(len(s)):

    if s[i]=="A":

        a=i

        break

for i in range(len(s)-1,-1,-1):

    if s[i]=="Z":

        z=i

        break

print((z-a+1))

s = list(eval(input()))
a_index = 0
z_index = 0
max_z_index = 0
for i in range(len(s)):
    if s[i] == "A":
        a_index = i
        break
for j in range(len(s)):
    if j <= a_index:
        continue
    else:
        if s[j] == "Z":
            z_index = j
            max_z_index = max(max_z_index, z_index)
print((max_z_index - a_index + 1))

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

-s = list(eval(input())) -a_index = 0 -z_index = 0 -max_z_index = 0 +s = eval(input()) +a = 0 +z = 0 -        a_index = i +        a = i -for j in range(len(s)): -    if j <= a_index: -        continue -    else: -        if s[j] == "Z": -            z_index = j -            max_z_index = max(max_z_index, z_index) -print((max_z_index - a_index + 1)) +for i in range(len(s) - 1, -1, -1): +    if s[i] == "Z": +        z = i +        break +print((z - a + 1))