s=eval(input())

for i in range(len(s)):

    if s[i]=="A":

        a=i

        break

for i in range(len(s)):

    if s[-i-1]=="Z":

        print((len(s)-i-a))

        break

s=eval(input())

l=len(s)

a,b=0,l-1

for i in range(l):

    if s[i]=="A":

        a=i

        break

for i in range(l-1,-1,-1):

    if s[i]=="Z":

        b=i

        break

print((b-a+1))

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

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

-for i in range(len(s)): +l = len(s) +a, b = 0, l - 1 +for i in range(l): -for i in range(len(s)): -    if s[-i - 1] == "Z": -        print((len(s) - i - a)) +for i in range(l - 1, -1, -1): +    if s[i] == "Z": +        b = i +print((b - a + 1))