sa, sb, sc = [eval(input()) for i in range(3)]

sa = [str(i) for i in sa]

sb = [str(i) for i in sb]

sc = [str(i) for i in sc]

play = len(sa+sb+sc)

    

next = eval("s" + sa.pop(0))



for i in range(1, play+1):

    if next == []:

        last = next

        break

    next = eval("s" + next.pop(0))



if last is sa:

    print("A")

elif last is sb:

    print("B")

else:

    print("C")

s = {"a": list(eval(input())), "b": list(eval(input())), "c": list(eval(input()))}



next = "a"

while s[next] != []:

    next = s[next].pop(0)



print((next.upper()))

sa, sb, sc = [eval(input()) for i in range(3)]
sa = [str(i) for i in sa]
sb = [str(i) for i in sb]
sc = [str(i) for i in sc]
play = len(sa + sb + sc)
next = eval("s" + sa.pop(0))
for i in range(1, play + 1):
    if next == []:
        last = next
        break
    next = eval("s" + next.pop(0))
if last is sa:
    print("A")
elif last is sb:
    print("B")
else:
    print("C")

s = {"a": list(eval(input())), "b": list(eval(input())), "c": list(eval(input()))}
next = "a"
while s[next] != []:
    next = s[next].pop(0)
print((next.upper()))

-sa, sb, sc = [eval(input()) for i in range(3)] -sa = [str(i) for i in sa] -sb = [str(i) for i in sb] -sc = [str(i) for i in sc] -play = len(sa + sb + sc) -next = eval("s" + sa.pop(0)) -for i in range(1, play + 1): -    if next == []: -        last = next -        break -    next = eval("s" + next.pop(0)) -if last is sa: -    print("A") -elif last is sb: -    print("B") -else: -    print("C") +s = {"a": list(eval(input())), "b": list(eval(input())), "c": list(eval(input()))} +next = "a" +while s[next] != []: +    next = s[next].pop(0) +print((next.upper()))