s = eval(input())



for i in range(len(s)):

  if s[i] == 'A':

    f = i

    break

for i in range(len(s)):

  if s[i] == 'Z':

    e = i

    

print((e-f+1))

s = eval(input())



print((len(s) - list(reversed(list(s))).index('Z') - s.index('A')))

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

s = eval(input())
print((len(s) - list(reversed(list(s))).index("Z") - s.index("A")))

-for i in range(len(s)): -    if s[i] == "A": -        f = i -        break -for i in range(len(s)): -    if s[i] == "Z": -        e = i -print((e - f + 1)) +print((len(s) - list(reversed(list(s))).index("Z") - s.index("A")))