s = str(eval(input()))



a = 199999

z = 0



for i in range(len(s)):

    if s[i] == "A":

        a = min(a,i)



    elif s[i]  == "Z":

        z = max(z,i)



print((z - a + 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()))
a = 199999
z = 0
for i in range(len(s)):
    if s[i] == "A":
        a = min(a, i)
    elif s[i] == "Z":
        z = max(z, i)
print((z - a + 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))

-a = 199999 +a = s.find("A") -    if s[i] == "A": -        a = min(a, i) -    elif s[i] == "Z": +    if s[i] == "Z":