s = eval(input())

list_s = list(s)



a_num = len(s)

z_num = -1



for i in range(len(s)):

    if list_s[i] == "A":

        if a_num > i:

            a_num = i



    if list_s[i] == "Z":

        z_num = i



print((z_num - a_num + 1))
s = eval(input())

list_s = list(s)



a_num = -1

z_num = -1



for i in range(len(s)):

    if list_s[i] == "A":

        a_num = i

        break



for j in range(len(s)):

    if list_s[j] == "Z":

        z_num = j



print((z_num - a_num + 1))
s = eval(input())
list_s = list(s)
a_num = len(s)
z_num = -1
for i in range(len(s)):
    if list_s[i] == "A":
        if a_num > i:
            a_num = i
    if list_s[i] == "Z":
        z_num = i
print((z_num - a_num + 1))

s = eval(input())
list_s = list(s)
a_num = -1
z_num = -1
for i in range(len(s)):
    if list_s[i] == "A":
        a_num = i
        break
for j in range(len(s)):
    if list_s[j] == "Z":
        z_num = j
print((z_num - a_num + 1))

-a_num = len(s) +a_num = -1 -        if a_num > i: -            a_num = i -    if list_s[i] == "Z": -        z_num = i +        a_num = i +        break +for j in range(len(s)): +    if list_s[j] == "Z": +        z_num = j