from collections import deque



A = deque(list(eval(input())))

B = deque(list(eval(input())))

C = deque(list(eval(input())))



def main(A, B, C):

    u = A.popleft()

    while True:

        if u == "a":

            if len(A) == 0:

                return "A"

            u = A.popleft()

        elif u == "b":

            if len(B) == 0:

                return "B"

            u = B.popleft()

        else:

            if len(C) == 0:

                return "C"

            u = C.popleft()



print((main(A, B, C)))



from collections import deque



A = deque(eval(input()))

B = deque(eval(input()))

C = deque(eval(input()))



def main(A, B, C):

    u = A.popleft()

    while True:

        if u == "a":

            if len(A) == 0:

                return "A"

            u = A.popleft()

        elif u == "b":

            if len(B) == 0:

                return "B"

            u = B.popleft()

        else:

            if len(C) == 0:

                return "C"

            u = C.popleft()



print((main(A, B, C)))



from collections import deque

A = deque(list(eval(input())))
B = deque(list(eval(input())))
C = deque(list(eval(input())))


def main(A, B, C):
    u = A.popleft()
    while True:
        if u == "a":
            if len(A) == 0:
                return "A"
            u = A.popleft()
        elif u == "b":
            if len(B) == 0:
                return "B"
            u = B.popleft()
        else:
            if len(C) == 0:
                return "C"
            u = C.popleft()


print((main(A, B, C)))

from collections import deque

A = deque(eval(input()))
B = deque(eval(input()))
C = deque(eval(input()))


def main(A, B, C):
    u = A.popleft()
    while True:
        if u == "a":
            if len(A) == 0:
                return "A"
            u = A.popleft()
        elif u == "b":
            if len(B) == 0:
                return "B"
            u = B.popleft()
        else:
            if len(C) == 0:
                return "C"
            u = C.popleft()


print((main(A, B, C)))

-A = deque(list(eval(input()))) -B = deque(list(eval(input()))) -C = deque(list(eval(input()))) +A = deque(eval(input())) +B = deque(eval(input())) +C = deque(eval(input()))