s = eval(input())

i = 0

while i < len(s) and s[i] != "A":

    i += 1



j = len(s) - 1

while j > 0 and s[j] != "Z":

    j -= 1



print((j - i + 1))
S = eval(input())

N = len(S)

s, t = 0, 0

for i in range(N):

    if S[i] == "A":

        s = i

        break



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

    if S[i] == "Z":

        t = i

        break



print((t - s + 1))
s = eval(input())
i = 0
while i < len(s) and s[i] != "A":
    i += 1
j = len(s) - 1
while j > 0 and s[j] != "Z":
    j -= 1
print((j - i + 1))

S = eval(input())
N = len(S)
s, t = 0, 0
for i in range(N):
    if S[i] == "A":
        s = i
        break
for i in range(N - 1, -1, -1):
    if S[i] == "Z":
        t = i
        break
print((t - s + 1))

-s = eval(input()) -i = 0 -while i < len(s) and s[i] != "A": -    i += 1 -j = len(s) - 1 -while j > 0 and s[j] != "Z": -    j -= 1 -print((j - i + 1)) +S = eval(input()) +N = len(S) +s, t = 0, 0 +for i in range(N): +    if S[i] == "A": +        s = i +        break +for i in range(N - 1, -1, -1): +    if S[i] == "Z": +        t = i +        break +print((t - s + 1))