s = list(eval(input()))

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

l = len(a) - a.index('A') - a[::-1].index('Z')

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

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

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