s = eval(input())

start = 0

end = 0

start = s.find('A')

for i in range(len(s)):

    if 'Z' in s[i]:

        if end <= i:

            end = i

print((end - start + 1))
s = eval(input())

for i in range(len(s)):

    if s[i] == 'A':

        Ai = i

        break

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

    if s[i] == 'Z':

        Zi = i

        break

print((Zi-Ai+1))

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

s = eval(input())
for i in range(len(s)):
    if s[i] == "A":
        Ai = i
        break
for i in range(len(s))[::-1]:
    if s[i] == "Z":
        Zi = i
        break
print((Zi - Ai + 1))

-start = 0 -end = 0 -start = s.find("A") -    if "Z" in s[i]: -        if end <= i: -            end = i -print((end - start + 1)) +    if s[i] == "A": +        Ai = i +        break +for i in range(len(s))[::-1]: +    if s[i] == "Z": +        Zi = i +        break +print((Zi - Ai + 1))