s = eval(input())



ans = ''

idx = -1

for i, c in enumerate(s):

    if c == 'A' and idx == -1:

        idx = i

    if c == 'Z':

        ans = s[idx:i+1]

print((len(ans)))

s = eval(input())



ans = ''

idx = -1

for i, c in enumerate(s):

    if c == 'A' and idx == -1:

        idx = i

        break

for i, c in enumerate(reversed(s)):

    if c == 'Z':

        ans = s[idx:len(s)-i]

        break

print((len(ans)))

s = eval(input())
ans = ""
idx = -1
for i, c in enumerate(s):
    if c == "A" and idx == -1:
        idx = i
    if c == "Z":
        ans = s[idx : i + 1]
print((len(ans)))

s = eval(input())
ans = ""
idx = -1
for i, c in enumerate(s):
    if c == "A" and idx == -1:
        idx = i
        break
for i, c in enumerate(reversed(s)):
    if c == "Z":
        ans = s[idx : len(s) - i]
        break
print((len(ans)))

+        break +for i, c in enumerate(reversed(s)): -        ans = s[idx : i + 1] +        ans = s[idx : len(s) - i] +        break