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

from collections import deque





def main():

    S = {s: deque(list(input().rstrip())) for s in ("a", "b", "c")}

    cur = S["a"].popleft()

    while S[cur]:  # search greedily

        cur = S[cur].popleft()

    print((cur.upper()))





if __name__ == "__main__":

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

def main():

    S = {s: list(input().rstrip())[::-1] for s in ("a", "b", "c")}

    cur = "a"

    while S[cur]:  # search greedily

        cur = S[cur].pop()

    print((cur.upper()))





if __name__ == "__main__":

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


def main():
    S = {s: deque(list(input().rstrip())) for s in ("a", "b", "c")}
    cur = S["a"].popleft()
    while S[cur]:  # search greedily
        cur = S[cur].popleft()
    print((cur.upper()))


if __name__ == "__main__":
    main()

# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
def main():
    S = {s: list(input().rstrip())[::-1] for s in ("a", "b", "c")}
    cur = "a"
    while S[cur]:  # search greedily
        cur = S[cur].pop()
    print((cur.upper()))


if __name__ == "__main__":
    main()

-from collections import deque - - -    S = {s: deque(list(input().rstrip())) for s in ("a", "b", "c")} -    cur = S["a"].popleft() +    S = {s: list(input().rstrip())[::-1] for s in ("a", "b", "c")} +    cur = "a" -        cur = S[cur].popleft() +        cur = S[cur].pop()