s = list(eval(input()))

a_index = s.index("A")

z_index = s[::-1].index("Z")

print((len(s) - (z_index) - a_index))

s = eval(input())

A = s.index("A")

Z = s[::-1].index("Z")

print((len(s) - Z - A))

s = list(eval(input()))
a_index = s.index("A")
z_index = s[::-1].index("Z")
print((len(s) - (z_index) - a_index))

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

-s = list(eval(input())) -a_index = s.index("A") -z_index = s[::-1].index("Z") -print((len(s) - (z_index) - a_index)) +s = eval(input()) +A = s.index("A") +Z = s[::-1].index("Z") +print((len(s) - Z - A))