sa = eval(input())

sb = eval(input())

sc = eval(input())



card = sa[0]

sa = sa[1:]

while 1:

	if card == "a":

		if not sa:

			print("A")

			break

		else:

			card = sa[0]

			sa = sa[1:]

	elif card == "b":

		if not sb:

			print("B")

			break

		else:

			card = sb[0]

			sb = sb[1:]

	else:

		if not sc:

			print("C")

			break

		else:

			card = sc[0]

			sc = sc[1:]

sa = eval(input())

sb = eval(input())

sc = eval(input())

players = {"a":sa, "b":sb, "c":sc}

if sa[0] == "a":

	p = "a"

	sa = sa[1:]

elif sb[0] == "b":

	p = "b"

	sb = sb[1:]

else:

	p = "c"

	sc = sc[1:]

while players["a"] or players["b"] or players["c"]:

	if not players[p]:

		print((p.upper()))

		exit()

	card = players[p][0]

	players[p] = players[p][1:]

	p = card

sa = eval(input())
sb = eval(input())
sc = eval(input())
card = sa[0]
sa = sa[1:]
while 1:
    if card == "a":
        if not sa:
            print("A")
            break
        else:
            card = sa[0]
            sa = sa[1:]
    elif card == "b":
        if not sb:
            print("B")
            break
        else:
            card = sb[0]
            sb = sb[1:]
    else:
        if not sc:
            print("C")
            break
        else:
            card = sc[0]
            sc = sc[1:]

sa = eval(input())
sb = eval(input())
sc = eval(input())
players = {"a": sa, "b": sb, "c": sc}
if sa[0] == "a":
    p = "a"
    sa = sa[1:]
elif sb[0] == "b":
    p = "b"
    sb = sb[1:]
else:
    p = "c"
    sc = sc[1:]
while players["a"] or players["b"] or players["c"]:
    if not players[p]:
        print((p.upper()))
        exit()
    card = players[p][0]
    players[p] = players[p][1:]
    p = card

-card = sa[0] -sa = sa[1:] -while 1: -    if card == "a": -        if not sa: -            print("A") -            break -        else: -            card = sa[0] -            sa = sa[1:] -    elif card == "b": -        if not sb: -            print("B") -            break -        else: -            card = sb[0] -            sb = sb[1:] -    else: -        if not sc: -            print("C") -            break -        else: -            card = sc[0] -            sc = sc[1:] +players = {"a": sa, "b": sb, "c": sc} +if sa[0] == "a": +    p = "a" +    sa = sa[1:] +elif sb[0] == "b": +    p = "b" +    sb = sb[1:] +else: +    p = "c" +    sc = sc[1:] +while players["a"] or players["b"] or players["c"]: +    if not players[p]: +        print((p.upper())) +        exit() +    card = players[p][0] +    players[p] = players[p][1:] +    p = card