s = eval(input())

a = -1

z = 0

for i in range(len(s)):

  if s[i] == "A" and a == -1:

    a = i

  if s[-(i + 1)] == "Z" and z == 0:

    z = len(s) - (i + 1)

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



a = -1

z = 0

for i in range(len(s)):

  if s[i] == "A" and a == -1:

    a = i

  elif s[i] == "Z":

    z = i

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

s = list(eval(input()))
a = -1
z = 0
for i in range(len(s)):
    if s[i] == "A" and a == -1:
        a = i
    elif s[i] == "Z":
        z = i
print((z - a + 1))

-s = eval(input()) +s = list(eval(input())) -    if s[-(i + 1)] == "Z" and z == 0: -        z = len(s) - (i + 1) +    elif s[i] == "Z": +        z = i