s = eval(input())



start = s.find("A")

end = s.rfind("Z")



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

n=s.index("A")

s=s[::-1]

e=s.index("Z")

print(len(s) - n -e)
s = eval(input())
start = s.find("A")
end = s.rfind("Z")
print((end - start + 1))

s = input()
n = s.index("A")
s = s[::-1]
e = s.index("Z")
print(len(s) - n - e)

-s = eval(input()) -start = s.find("A") -end = s.rfind("Z") -print((end - start + 1)) +s = input() +n = s.index("A") +s = s[::-1] +e = s.index("Z") +print(len(s) - n - e)