S = eval(input())

#Aの探索

for i in range(len(S)):

    if S[i] == "A":

        S = S[i:]

        break



#Zの探索

if S[-1] == "Z":

    print((len(S)))

    exit()

for i in range(1, len(S)+1):

    if S[-i] == "Z":

        S = S[:-i+1]

        break

print((len(S)))
S = eval(input())

a_ind = S.find("A")

z_ind = S.rfind("Z")

print((z_ind - a_ind + 1))
S = eval(input())
# Aの探索
for i in range(len(S)):
    if S[i] == "A":
        S = S[i:]
        break
# Zの探索
if S[-1] == "Z":
    print((len(S)))
    exit()
for i in range(1, len(S) + 1):
    if S[-i] == "Z":
        S = S[: -i + 1]
        break
print((len(S)))

S = eval(input())
a_ind = S.find("A")
z_ind = S.rfind("Z")
print((z_ind - a_ind + 1))

-# Aの探索 -for i in range(len(S)): -    if S[i] == "A": -        S = S[i:] -        break -# Zの探索 -if S[-1] == "Z": -    print((len(S))) -    exit() -for i in range(1, len(S) + 1): -    if S[-i] == "Z": -        S = S[: -i + 1] -        break -print((len(S))) +a_ind = S.find("A") +z_ind = S.rfind("Z") +print((z_ind - a_ind + 1))