s = list(eval(input()))

a = 0

z = 0

for i in range(len(s)):

    if s[i] == 'A':

        a = i+1

        break

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

    if s[-i] == 'Z':

        z = len(s)-i+1

        break

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

a = s.index('A')

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

z = len(s) - z

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

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

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