# -*- coding: utf-8 -*-



a = eval(input())

b = eval(input())

c = eval(input())

sa = [a[i] for i in range(len(a))]

sb = [b[i] for i in range(len(b))]

sc = [c[i] for i in range(len(c))]

turn = sa[0]

while True:

    if turn == 'a':

        if len(sa) == 0:

            print("A")

            break

        turn = sa[0]

        sa.pop(0)

    if turn == 'b':

        if len(sb) == 0:

            print("B")

            break

        turn = sb[0]

        sb.pop(0)

    if turn == 'c':

        if len(sc) == 0:

            print("C")

            break

        turn = sc[0]

        sc.pop(0)
a = eval(input())

b = eval(input())

c = eval(input())

sa = [i for i in a]

sb = [i for i in b]

sc = [i for i in c]

turn = sa[0]

while True:

    if turn == 'a':

        if len(sa) == 0:

            print('A')

            break

        turn = sa[0]

        sa.pop(0)

    if turn == 'b':

        if len(sb) == 0:

            print('B')

            break

        turn = sb[0]

        sb.pop(0)

    if turn == 'c':

        if len(sc) == 0:

            print('C')

            break

        turn = sc[0]

        sc.pop(0)
# -*- coding: utf-8 -*-
a = eval(input())
b = eval(input())
c = eval(input())
sa = [a[i] for i in range(len(a))]
sb = [b[i] for i in range(len(b))]
sc = [c[i] for i in range(len(c))]
turn = sa[0]
while True:
    if turn == "a":
        if len(sa) == 0:
            print("A")
            break
        turn = sa[0]
        sa.pop(0)
    if turn == "b":
        if len(sb) == 0:
            print("B")
            break
        turn = sb[0]
        sb.pop(0)
    if turn == "c":
        if len(sc) == 0:
            print("C")
            break
        turn = sc[0]
        sc.pop(0)

a = eval(input())
b = eval(input())
c = eval(input())
sa = [i for i in a]
sb = [i for i in b]
sc = [i for i in c]
turn = sa[0]
while True:
    if turn == "a":
        if len(sa) == 0:
            print("A")
            break
        turn = sa[0]
        sa.pop(0)
    if turn == "b":
        if len(sb) == 0:
            print("B")
            break
        turn = sb[0]
        sb.pop(0)
    if turn == "c":
        if len(sc) == 0:
            print("C")
            break
        turn = sc[0]
        sc.pop(0)

-# -*- coding: utf-8 -*- -sa = [a[i] for i in range(len(a))] -sb = [b[i] for i in range(len(b))] -sc = [c[i] for i in range(len(c))] +sa = [i for i in a] +sb = [i for i in b] +sc = [i for i in c]