s = eval(input())



for i in range(len(s)):

  if s[i] == 'A':

    a = i

    break

for k in range(len(s)-1, -1, -1):

  if s[k] == 'Z':

    b = k

    break



print((b - a + 1 ))
s = eval(input())

a = s.find('A')

b = s.rfind('Z')

print((b-a+1))
s = eval(input())
for i in range(len(s)):
    if s[i] == "A":
        a = i
        break
for k in range(len(s) - 1, -1, -1):
    if s[k] == "Z":
        b = k
        break
print((b - a + 1))

s = eval(input())
a = s.find("A")
b = s.rfind("Z")
print((b - a + 1))

-for i in range(len(s)): -    if s[i] == "A": -        a = i -        break -for k in range(len(s) - 1, -1, -1): -    if s[k] == "Z": -        b = k -        break +a = s.find("A") +b = s.rfind("Z")