s = eval(input())

flag = True

for i in range(len(s)):

    if s[i] == "A" and flag :

        a = i

        flag = False

    if s[i] == "Z" and not flag:

        z = i

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

flag = True

for i in range(len(s)):

    if s[i] == "A":

        a = i

        break

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

    if s[i] == "Z":

        z = i

        break    

print((z-a+1))
s = eval(input())
flag = True
for i in range(len(s)):
    if s[i] == "A" and flag:
        a = i
        flag = False
    if s[i] == "Z" and not flag:
        z = i
print((z - a + 1))

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

-    if s[i] == "A" and flag: +    if s[i] == "A": -        flag = False -    if s[i] == "Z" and not flag: +        break +for i in range(len(s) - 1, 0, -1): +    if s[i] == "Z": +        break