# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)

from collections import deque



lst = [deque(list(input().rstrip())) for _ in range(3)]

abc = ["a", "b", "c"]

turn = lst[0].popleft()



while True:

    if not lst[abc.index(turn)]:

        print((turn.upper()))

        break

    turn = lst[abc.index(turn)].popleft()
# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)

from collections import deque





def main():

    S = [deque(list(input().rstrip())) for _ in range(3)]

    abc = {"a": 0, "b": 1, "c": 2}

    cur = S[0].popleft()

    while True:  # search greedily

        idx = abc[cur]

        if not S[idx]:

            print((cur.upper()))

            break

        cur = S[idx].popleft()





if __name__ == "__main__":

    main()
# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
from collections import deque

lst = [deque(list(input().rstrip())) for _ in range(3)]
abc = ["a", "b", "c"]
turn = lst[0].popleft()
while True:
    if not lst[abc.index(turn)]:
        print((turn.upper()))
        break
    turn = lst[abc.index(turn)].popleft()

# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
from collections import deque


def main():
    S = [deque(list(input().rstrip())) for _ in range(3)]
    abc = {"a": 0, "b": 1, "c": 2}
    cur = S[0].popleft()
    while True:  # search greedily
        idx = abc[cur]
        if not S[idx]:
            print((cur.upper()))
            break
        cur = S[idx].popleft()


if __name__ == "__main__":
    main()

-lst = [deque(list(input().rstrip())) for _ in range(3)] -abc = ["a", "b", "c"] -turn = lst[0].popleft() -while True: -    if not lst[abc.index(turn)]: -        print((turn.upper())) -        break -    turn = lst[abc.index(turn)].popleft() + +def main(): +    S = [deque(list(input().rstrip())) for _ in range(3)] +    abc = {"a": 0, "b": 1, "c": 2} +    cur = S[0].popleft() +    while True:  # search greedily +        idx = abc[cur] +        if not S[idx]: +            print((cur.upper())) +            break +        cur = S[idx].popleft() + + +if __name__ == "__main__": +    main()