s = input()

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

s = input()

print((s).rindex('Z') - s.index('A') + 1)

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

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

-print(len(s) - "".join(reversed(s)).index("Z") - s.index("A")) +print((s).rindex("Z") - s.index("A") + 1)