S = eval(input())

a = []

z = []

for i, s in enumerate(S):

    if s == 'A':

        a.append(i + 1)

    elif s == 'Z':

        z.append(i + 1)



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

a = s.index('A')

z = s.rindex('Z')

print((z - a + 1))
S = eval(input())
a = []
z = []
for i, s in enumerate(S):
    if s == "A":
        a.append(i + 1)
    elif s == "Z":
        z.append(i + 1)
print((max(z) - min(a) + 1))

s = eval(input())
a = s.index("A")
z = s.rindex("Z")
print((z - a + 1))

-S = eval(input()) -a = [] -z = [] -for i, s in enumerate(S): -    if s == "A": -        a.append(i + 1) -    elif s == "Z": -        z.append(i + 1) -print((max(z) - min(a) + 1)) +s = eval(input()) +a = s.index("A") +z = s.rindex("Z") +print((z - a + 1))