s = eval(input())



start = -1

end = 0

for i in range(len(s)):

    if s[i] == 'A' and start < 0:

        start = i

    elif s[i] == 'Z':

        end = i

print((end - start + 1))

s = eval(input())



start = 0

for i in range(len(s)):

    if s[i] == 'A':

        start = i

        break



end = 0

for i in reversed(list(range(len(s)))):

    if s[i] == 'Z':

        end = i

        break

print((end - start + 1))

s = eval(input())
start = -1
end = 0
for i in range(len(s)):
    if s[i] == "A" and start < 0:
        start = i
    elif s[i] == "Z":
        end = i
print((end - start + 1))

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

-start = -1 +start = 0 +for i in range(len(s)): +    if s[i] == "A": +        start = i +        break -for i in range(len(s)): -    if s[i] == "A" and start < 0: -        start = i -    elif s[i] == "Z": +for i in reversed(list(range(len(s)))): +    if s[i] == "Z": +        break