SA = eval(input())

SB = eval(input())

SC = eval(input())



pointer = SA[0]

SA = SA[1:]

d = {'a': SA, 'b': SB, 'c': SC}



while True:

    if d[pointer] == '':

        ans = pointer

        break

    tmp = d[pointer][0]

    d[pointer] = d[pointer][1:]

    pointer = tmp



print((ans.upper()))
d = { 'a':eval(input()), 'b':eval(input()), 'c':eval(input()) }

pointer = 'a'

while True:

    if 0 < len(d[pointer]):

        tmp = d[pointer][0]

        d[pointer] = d[pointer][1:]

        pointer = tmp

    else:

        print((pointer.upper()))

        break

SA = eval(input())
SB = eval(input())
SC = eval(input())
pointer = SA[0]
SA = SA[1:]
d = {"a": SA, "b": SB, "c": SC}
while True:
    if d[pointer] == "":
        ans = pointer
        break
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp
print((ans.upper()))

d = {"a": eval(input()), "b": eval(input()), "c": eval(input())}
pointer = "a"
while True:
    if 0 < len(d[pointer]):
        tmp = d[pointer][0]
        d[pointer] = d[pointer][1:]
        pointer = tmp
    else:
        print((pointer.upper()))
        break

-SA = eval(input()) -SB = eval(input()) -SC = eval(input()) -pointer = SA[0] -SA = SA[1:] -d = {"a": SA, "b": SB, "c": SC} +d = {"a": eval(input()), "b": eval(input()), "c": eval(input())} +pointer = "a" -    if d[pointer] == "": -        ans = pointer +    if 0 < len(d[pointer]): +        tmp = d[pointer][0] +        d[pointer] = d[pointer][1:] +        pointer = tmp +    else: +        print((pointer.upper())) -    tmp = d[pointer][0] -    d[pointer] = d[pointer][1:] -    pointer = tmp -print((ans.upper()))