s = eval(input())

a = s.index("A")



rs = ''.join(reversed(s))

z = rs.index("Z")



print((len(s) - a - z))
s = eval(input())

a = s.index("A")



rs = s[::-1]

z = rs.index("Z")



print((len(s) - a - z))
s = eval(input())
a = s.index("A")
rs = "".join(reversed(s))
z = rs.index("Z")
print((len(s) - a - z))

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

-rs = "".join(reversed(s)) +rs = s[::-1]