s = eval(input())

isAdd = False

l = -1

r = -1

for i in range(len(s)):

    if s[i] == 'A' and l == -1: l = i

    if s[len(s)-1-i] == 'Z' and r == -1: r = len(s)-1-i



print((r-l+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())
isAdd = False
l = -1
r = -1
for i in range(len(s)):
    if s[i] == "A" and l == -1:
        l = i
    if s[len(s) - 1 - i] == "Z" and r == -1:
        r = len(s) - 1 - i
print((r - l + 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))

-isAdd = False -l = -1 -r = -1 -for i in range(len(s)): -    if s[i] == "A" and l == -1: -        l = i -    if s[len(s) - 1 - i] == "Z" and r == -1: -        r = len(s) - 1 - i +r = len(s) - 1 +l = 0 +while s[l] != "A": +    l += 1 +while s[r] != "Z": +    r -= 1