s = list(eval(input()))



begin = 0

for i in range(len(s)):

    if s[i] == "A":

        begin = i

        break

end = 0

for i in reversed(list(range(len(s)))):

    if s[i] == "Z":

        end = i

        break



print((end - begin + 1))
s = eval(input())



begin = 0

for i in range(len(s)):

    if s[i] == "A":

        begin = i

        break

end = 0

for i in reversed(list(range(len(s)))):

    if s[i] == "Z":

        end = i

        break



print((end - begin + 1))
s = list(eval(input()))
begin = 0
for i in range(len(s)):
    if s[i] == "A":
        begin = i
        break
end = 0
for i in reversed(list(range(len(s)))):
    if s[i] == "Z":
        end = i
        break
print((end - begin + 1))

s = eval(input())
begin = 0
for i in range(len(s)):
    if s[i] == "A":
        begin = i
        break
end = 0
for i in reversed(list(range(len(s)))):
    if s[i] == "Z":
        end = i
        break
print((end - begin + 1))

-s = list(eval(input())) +s = eval(input())