s = list(eval(input()))



for i,j in enumerate(s):

    if j == 'A':

        a = i

        break

for i,j in enumerate(s):

    if j == 'Z':

        z = i

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



first = s.index('A')

end = s.rindex('Z')



ans = end - first + 1

print(ans)
s = list(eval(input()))
for i, j in enumerate(s):
    if j == "A":
        a = i
        break
for i, j in enumerate(s):
    if j == "Z":
        z = i
print((z - a + 1))

s = eval(input())
first = s.index("A")
end = s.rindex("Z")
ans = end - first + 1
print(ans)

-s = list(eval(input())) -for i, j in enumerate(s): -    if j == "A": -        a = i -        break -for i, j in enumerate(s): -    if j == "Z": -        z = i -print((z - a + 1)) +s = eval(input()) +first = s.index("A") +end = s.rindex("Z") +ans = end - first + 1 +print(ans)