s = eval(input())

r = len(s) - 1

l = 0

while (s[l] != 'A'): l+=1

while (s[r] != 'Z'): r-=1

print((r-l+1))

s = eval(input())

order_a=s.find('A')

order_z=s.rfind('Z')

print((order_z - order_a + 1))

s = eval(input())
r = len(s) - 1
l = 0
while s[l] != "A":
    l += 1
while s[r] != "Z":
    r -= 1
print((r - l + 1))

s = eval(input())
order_a = s.find("A")
order_z = s.rfind("Z")
print((order_z - order_a + 1))

-r = len(s) - 1 -l = 0 -while s[l] != "A": -    l += 1 -while s[r] != "Z": -    r -= 1 -print((r - l + 1)) +order_a = s.find("A") +order_z = s.rfind("Z") +print((order_z - order_a + 1))