s = str(eval(input()))



z = 0



a = s.find("A")



for i in range(len(s)):

  if s[i]  == "Z":

    z = max(z,i)



print((z - a + 1))
s = str(eval(input()))

cnt_1, cnt_2 = 0, 0

for i in range(len(s)):

    if s[i] == 'A':

        cnt_1 = i

        break

for i in range(len(s)):

    if s[i] == 'Z':

        cnt_2 = i

print((cnt_2 - cnt_1 + 1))
s = str(eval(input()))
z = 0
a = s.find("A")
for i in range(len(s)):
    if s[i] == "Z":
        z = max(z, i)
print((z - a + 1))

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

-z = 0 -a = s.find("A") +cnt_1, cnt_2 = 0, 0 +for i in range(len(s)): +    if s[i] == "A": +        cnt_1 = i +        break -        z = max(z, i) -print((z - a + 1)) +        cnt_2 = i +print((cnt_2 - cnt_1 + 1))