sa = eval(input())

sb = eval(input())

sc = eval(input())



ai = bi = ci = -1

turn = 'a'

while True:

    exec(turn + 'i += 1')

    turn = eval('s' + turn + '[' + turn + 'i-1]')

    if eval(turn + 'i == len(s' + turn + ')'):

        print((turn.upper()))

        exit()
A = eval(input())

B = eval(input())

C = eval(input())



ai = bi = ci = 0

turn = 'a'

while 1:

    if turn == 'a':

        if ai >= len(A):

            print('A')

            exit()

        turn = A[ai]

        ai += 1

    elif turn == 'b':

        if bi >= len(B):

            print('B')

            exit()

        turn = B[bi]

        bi += 1

    else:

        if ci >= len(C):

            print('C')

            exit()

        turn = C[ci]

        ci += 1
sa = eval(input())
sb = eval(input())
sc = eval(input())
ai = bi = ci = -1
turn = "a"
while True:
    exec(turn + "i += 1")
    turn = eval("s" + turn + "[" + turn + "i-1]")
    if eval(turn + "i == len(s" + turn + ")"):
        print((turn.upper()))
        exit()

A = eval(input())
B = eval(input())
C = eval(input())
ai = bi = ci = 0
turn = "a"
while 1:
    if turn == "a":
        if ai >= len(A):
            print("A")
            exit()
        turn = A[ai]
        ai += 1
    elif turn == "b":
        if bi >= len(B):
            print("B")
            exit()
        turn = B[bi]
        bi += 1
    else:
        if ci >= len(C):
            print("C")
            exit()
        turn = C[ci]
        ci += 1

-sa = eval(input()) -sb = eval(input()) -sc = eval(input()) -ai = bi = ci = -1 +A = eval(input()) +B = eval(input()) +C = eval(input()) +ai = bi = ci = 0 -while True: -    exec(turn + "i += 1") -    turn = eval("s" + turn + "[" + turn + "i-1]") -    if eval(turn + "i == len(s" + turn + ")"): -        print((turn.upper())) -        exit() +while 1: +    if turn == "a": +        if ai >= len(A): +            print("A") +            exit() +        turn = A[ai] +        ai += 1 +    elif turn == "b": +        if bi >= len(B): +            print("B") +            exit() +        turn = B[bi] +        bi += 1 +    else: +        if ci >= len(C): +            print("C") +            exit() +        turn = C[ci] +        ci += 1