s = list(eval(input()))



a_ind = [i for i, v  in enumerate(s) if v == "A"]

z_ind = [i for i, v in enumerate(s) if v == "Z"]





ans = z_ind[-1] - a_ind[0] + 1



print(ans)
s = eval(input())

s_r = reversed(s)

s = list(s)

s_r = list(s_r)



a_ind = s.index("A")

z_ind = s_r.index("Z")

z_ind = len(s) - z_ind



ans = z_ind - a_ind



print(ans)
s = list(eval(input()))
a_ind = [i for i, v in enumerate(s) if v == "A"]
z_ind = [i for i, v in enumerate(s) if v == "Z"]
ans = z_ind[-1] - a_ind[0] + 1
print(ans)

s = eval(input())
s_r = reversed(s)
s = list(s)
s_r = list(s_r)
a_ind = s.index("A")
z_ind = s_r.index("Z")
z_ind = len(s) - z_ind
ans = z_ind - a_ind
print(ans)

-s = list(eval(input())) -a_ind = [i for i, v in enumerate(s) if v == "A"] -z_ind = [i for i, v in enumerate(s) if v == "Z"] -ans = z_ind[-1] - a_ind[0] + 1 +s = eval(input()) +s_r = reversed(s) +s = list(s) +s_r = list(s_r) +a_ind = s.index("A") +z_ind = s_r.index("Z") +z_ind = len(s) - z_ind +ans = z_ind - a_ind