# https://atcoder.jp/contests/abc053/tasks/abc053_b



s = eval(input())

n = len(s)

for i in range(n):

    if s[i] == 'A':

        start = i

        break

for i in range(n - 1, -1, -1):

    if s[i] == 'Z':

        end = i

        break

print((end + 1 - start))





s = eval(input())

n = len(s)

start = s.index('A')

end = n - s[::-1].index('Z')

print((len(s[start:end])))

# https://atcoder.jp/contests/abc053/tasks/abc053_b
s = eval(input())
n = len(s)
for i in range(n):
    if s[i] == "A":
        start = i
        break
for i in range(n - 1, -1, -1):
    if s[i] == "Z":
        end = i
        break
print((end + 1 - start))

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

-# https://atcoder.jp/contests/abc053/tasks/abc053_b -for i in range(n): -    if s[i] == "A": -        start = i -        break -for i in range(n - 1, -1, -1): -    if s[i] == "Z": -        end = i -        break -print((end + 1 - start)) +start = s.index("A") +end = n - s[::-1].index("Z") +print((len(s[start:end])))