str = eval(input(''))

start = -1

end = -1

for x in range(len(str)):

  if str[x] == 'A' and start == -1:

    start = x

  elif str[x] == 'Z':

    end = x

print((end - start + 1))
str = eval(input(''))

start = str.find('A')

end = str.rfind('Z')

print((end - start + 1))
str = eval(input(""))
start = -1
end = -1
for x in range(len(str)):
    if str[x] == "A" and start == -1:
        start = x
    elif str[x] == "Z":
        end = x
print((end - start + 1))

str = eval(input(""))
start = str.find("A")
end = str.rfind("Z")
print((end - start + 1))

-start = -1 -end = -1 -for x in range(len(str)): -    if str[x] == "A" and start == -1: -        start = x -    elif str[x] == "Z": -        end = x +start = str.find("A") +end = str.rfind("Z")