s = eval(input())



id_a = len(s)

id_z = 0

for i in range(len(s)):

  if s[i] == 'A':

    id_a = min(id_a, i)

  if s[i] == 'Z':

    id_z = max(id_z, i)

    

print((id_z - id_a + 1))

s =eval(input())

A=0

Z=0



for i in range(len(s)):

  if s[i] =="A":

    A +=(i+1)

    break



    

for j in range(len(s)):

  if s[-(j+1)] =="Z":

    Z +=len(s)-j

    break

    

print((Z-A+1))
s = eval(input())
id_a = len(s)
id_z = 0
for i in range(len(s)):
    if s[i] == "A":
        id_a = min(id_a, i)
    if s[i] == "Z":
        id_z = max(id_z, i)
print((id_z - id_a + 1))

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

-id_a = len(s) -id_z = 0 +A = 0 +Z = 0 -        id_a = min(id_a, i) -    if s[i] == "Z": -        id_z = max(id_z, i) -print((id_z - id_a + 1)) +        A += i + 1 +        break +for j in range(len(s)): +    if s[-(j + 1)] == "Z": +        Z += len(s) - j +        break +print((Z - A + 1))