Sa = list(eval(input()))

Sb = list(eval(input()))

Sc = list(eval(input()))

dic = {"a": Sa, "b": Sb, "c": Sc}

hiku = "a"

while True:

    try:

        sasareta = dic[hiku].pop(0)

    except IndexError:

        print((hiku.upper()))

        break

    hiku = sasareta

A = list(eval(input()))

B = list(eval(input()))

C = list(eval(input()))

now = "a"

d = {"a": A, "b": B, "c": C}

while A or B or C:

    if not d[now]:

        print((now.upper()))

        break

    else:

        now = d[now].pop(0)

Sa = list(eval(input()))
Sb = list(eval(input()))
Sc = list(eval(input()))
dic = {"a": Sa, "b": Sb, "c": Sc}
hiku = "a"
while True:
    try:
        sasareta = dic[hiku].pop(0)
    except IndexError:
        print((hiku.upper()))
        break
    hiku = sasareta

A = list(eval(input()))
B = list(eval(input()))
C = list(eval(input()))
now = "a"
d = {"a": A, "b": B, "c": C}
while A or B or C:
    if not d[now]:
        print((now.upper()))
        break
    else:
        now = d[now].pop(0)

-Sa = list(eval(input())) -Sb = list(eval(input())) -Sc = list(eval(input())) -dic = {"a": Sa, "b": Sb, "c": Sc} -hiku = "a" -while True: -    try: -        sasareta = dic[hiku].pop(0) -    except IndexError: -        print((hiku.upper())) +A = list(eval(input())) +B = list(eval(input())) +C = list(eval(input())) +now = "a" +d = {"a": A, "b": B, "c": C} +while A or B or C: +    if not d[now]: +        print((now.upper())) -    hiku = sasareta +    else: +        now = d[now].pop(0)