S = input()

if "A" not in S:

    print(-1)

else:

    ans = "A"

    for s in S[S.index("A") + 1:]:

        if ans[-1] == "A" and s == "Z": ans += s

        if ans[-1] == "Z" and s == "A": ans += s

    if ans[-1] == "A": ans = ans[:-1]

    print(ans if ans else -1)
S = input()

A = False

c = 0

for s in S:

    A |= s == "A"

    if s == "Z" and A:

        c += 1

        A = False

print("AZ"*c if c > 0 else -1)
S = input()
if "A" not in S:
    print(-1)
else:
    ans = "A"
    for s in S[S.index("A") + 1 :]:
        if ans[-1] == "A" and s == "Z":
            ans += s
        if ans[-1] == "Z" and s == "A":
            ans += s
    if ans[-1] == "A":
        ans = ans[:-1]
    print(ans if ans else -1)

S = input()
A = False
c = 0
for s in S:
    A |= s == "A"
    if s == "Z" and A:
        c += 1
        A = False
print("AZ" * c if c > 0 else -1)

-if "A" not in S: -    print(-1) -else: -    ans = "A" -    for s in S[S.index("A") + 1 :]: -        if ans[-1] == "A" and s == "Z": -            ans += s -        if ans[-1] == "Z" and s == "A": -            ans += s -    if ans[-1] == "A": -        ans = ans[:-1] -    print(ans if ans else -1) +A = False +c = 0 +for s in S: +    A |= s == "A" +    if s == "Z" and A: +        c += 1 +        A = False +print("AZ" * c if c > 0 else -1)