A = str(eval(input()))

B = str(eval(input()))

C = str(eval(input()))



p = 0

while True:

    if p == 0:

        if A == "":

            print("A")

            exit()

        if A[0] == "b":

            p = 1

        elif A[0] == "c":

            p = 2

        A = A[1:]

    elif p == 1:

        if B == "":

            print("B")

            exit()

        if B[0] == "a":

            p = 0

        elif B[0] == "c":

            p = 2

        B = B[1:]

    else:

        if C == "":

            print("C")

            exit()

        if C[0] == "b":

            p = 1

        elif C[0] == "a":

            p = 0

        C = C[1:]



A = [str(x) for x in eval(input())]

B = [str(x) for x in eval(input())]

C = [str(x) for x in eval(input())]

t = 0

c = ""

while True:

    if t == 0:

        if len(A) == 0:

            print("A")

            exit(0)

        else:

            c = A.pop(0)

    elif t == 1:

        if len(B) == 0:

            print("B")

            exit(0)

        else:

            c = B.pop(0)

    else:

        if len(C) == 0:

            print("C")

            exit(0)

        else:

            c = C.pop(0)



    if c == "a":

        t = 0

    elif c == "b":

        t = 1

    else:

        t = 2

A = str(eval(input()))
B = str(eval(input()))
C = str(eval(input()))
p = 0
while True:
    if p == 0:
        if A == "":
            print("A")
            exit()
        if A[0] == "b":
            p = 1
        elif A[0] == "c":
            p = 2
        A = A[1:]
    elif p == 1:
        if B == "":
            print("B")
            exit()
        if B[0] == "a":
            p = 0
        elif B[0] == "c":
            p = 2
        B = B[1:]
    else:
        if C == "":
            print("C")
            exit()
        if C[0] == "b":
            p = 1
        elif C[0] == "a":
            p = 0
        C = C[1:]

A = [str(x) for x in eval(input())]
B = [str(x) for x in eval(input())]
C = [str(x) for x in eval(input())]
t = 0
c = ""
while True:
    if t == 0:
        if len(A) == 0:
            print("A")
            exit(0)
        else:
            c = A.pop(0)
    elif t == 1:
        if len(B) == 0:
            print("B")
            exit(0)
        else:
            c = B.pop(0)
    else:
        if len(C) == 0:
            print("C")
            exit(0)
        else:
            c = C.pop(0)
    if c == "a":
        t = 0
    elif c == "b":
        t = 1
    else:
        t = 2

-A = str(eval(input())) -B = str(eval(input())) -C = str(eval(input())) -p = 0 +A = [str(x) for x in eval(input())] +B = [str(x) for x in eval(input())] +C = [str(x) for x in eval(input())] +t = 0 +c = "" -    if p == 0: -        if A == "": +    if t == 0: +        if len(A) == 0: -            exit() -        if A[0] == "b": -            p = 1 -        elif A[0] == "c": -            p = 2 -        A = A[1:] -    elif p == 1: -        if B == "": +            exit(0) +        else: +            c = A.pop(0) +    elif t == 1: +        if len(B) == 0: -            exit() -        if B[0] == "a": -            p = 0 -        elif B[0] == "c": -            p = 2 -        B = B[1:] +            exit(0) +        else: +            c = B.pop(0) -        if C == "": +        if len(C) == 0: -            exit() -        if C[0] == "b": -            p = 1 -        elif C[0] == "a": -            p = 0 -        C = C[1:] +            exit(0) +        else: +            c = C.pop(0) +    if c == "a": +        t = 0 +    elif c == "b": +        t = 1 +    else: +        t = 2