s = eval(input())



start = min(i for i, x in enumerate(s) if x == 'A')

end = max(j for j, y in enumerate(s) if y == 'Z')



print((end-start+1))
s = eval(input())



a = s.find('A')

#print(a)

z = 0

for i in range(len(s)):

  if s[i] == 'Z':

    z = i

#print(z)

print((z-a+1))
s = eval(input())
start = min(i for i, x in enumerate(s) if x == "A")
end = max(j for j, y in enumerate(s) if y == "Z")
print((end - start + 1))

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

-start = min(i for i, x in enumerate(s) if x == "A") -end = max(j for j, y in enumerate(s) if y == "Z") -print((end - start + 1)) +a = s.find("A") +# print(a) +z = 0 +for i in range(len(s)): +    if s[i] == "Z": +        z = i +# print(z) +print((z - a + 1))