s = eval(input())

A = s.index("A")

Z = 0

for i in range(len(s))[::-1]:

    if s[i] == "Z":

        Z = i

        break

print((Z-A+1))
s = eval(input())

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

s = eval(input())
print((s.rfind("Z") - s.find("A") + 1))

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