sa = input()

sb = input()

sc = input()

st = [sa,sb,sc]

lns = [len(sa),len(sb),len(sc)]

ind = [0,0,0]

cur = 0

done = False

winner = "a"

dumb = ["A","B","C"]

while (not done):

    if (ind[cur] >= lns[cur]):

        winner = dumb[cur]

        done = True

        break

    else:

        x = st[cur][ind[cur]]

        ind[cur] += 1

        if (x=="a"):

            cur = 0

        elif (x=="b"):

            cur = 1

        elif (x=="c"):

            cur = 2



print(str.upper(winner))
cards = []

for i in range(3):

	cards.append(input())

inds = [0,0,0]

win = ['A','B','C']

cur = 0

while True:

	if inds[cur] >= len(cards[cur]):

		print(win[cur])

		break

	else:

		temp = cards[cur][inds[cur]]

		inds[cur] += 1

		if temp == 'a':

			cur = 0

		elif temp == 'b':

			cur = 1

		else:

			cur = 2
sa = input()
sb = input()
sc = input()
st = [sa, sb, sc]
lns = [len(sa), len(sb), len(sc)]
ind = [0, 0, 0]
cur = 0
done = False
winner = "a"
dumb = ["A", "B", "C"]
while not done:
    if ind[cur] >= lns[cur]:
        winner = dumb[cur]
        done = True
        break
    else:
        x = st[cur][ind[cur]]
        ind[cur] += 1
        if x == "a":
            cur = 0
        elif x == "b":
            cur = 1
        elif x == "c":
            cur = 2
print(str.upper(winner))

cards = []
for i in range(3):
    cards.append(input())
inds = [0, 0, 0]
win = ["A", "B", "C"]
cur = 0
while True:
    if inds[cur] >= len(cards[cur]):
        print(win[cur])
        break
    else:
        temp = cards[cur][inds[cur]]
        inds[cur] += 1
        if temp == "a":
            cur = 0
        elif temp == "b":
            cur = 1
        else:
            cur = 2

-sa = input() -sb = input() -sc = input() -st = [sa, sb, sc] -lns = [len(sa), len(sb), len(sc)] -ind = [0, 0, 0] +cards = [] +for i in range(3): +    cards.append(input()) +inds = [0, 0, 0] +win = ["A", "B", "C"] -done = False -winner = "a" -dumb = ["A", "B", "C"] -while not done: -    if ind[cur] >= lns[cur]: -        winner = dumb[cur] -        done = True +while True: +    if inds[cur] >= len(cards[cur]): +        print(win[cur]) -        x = st[cur][ind[cur]] -        ind[cur] += 1 -        if x == "a": +        temp = cards[cur][inds[cur]] +        inds[cur] += 1 +        if temp == "a": -        elif x == "b": +        elif temp == "b": -        elif x == "c": +        else: -print(str.upper(winner))