s = eval(input())



for i in range(len(s)):

    if s[i] == "A":

        start = i

        break



for i in range(len(s))[::-1]:

    if s[i] == "Z":

        end = i

        break



ans = end - start + 1

print(ans)
s = eval(input())

ans = len(s[s.find("A"): s.rfind("Z")]) + 1

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

s = eval(input())
ans = len(s[s.find("A") : s.rfind("Z")]) + 1
print(ans)

-for i in range(len(s)): -    if s[i] == "A": -        start = i -        break -for i in range(len(s))[::-1]: -    if s[i] == "Z": -        end = i -        break -ans = end - start + 1 +ans = len(s[s.find("A") : s.rfind("Z")]) + 1