s=[list(eval(input()))for _ in[0]*3];i=0

while s[i]:i='abc'.index(s[i].pop(0))

print(('ABC'[i]))
d={i:list(eval(input()))for i in'abc'};i='a'

while d[i]:i=d[i].pop(0)

print((i.upper()))
s = [list(eval(input())) for _ in [0] * 3]
i = 0
while s[i]:
    i = "abc".index(s[i].pop(0))
print(("ABC"[i]))

d = {i: list(eval(input())) for i in "abc"}
i = "a"
while d[i]:
    i = d[i].pop(0)
print((i.upper()))

-s = [list(eval(input())) for _ in [0] * 3] -i = 0 -while s[i]: -    i = "abc".index(s[i].pop(0)) -print(("ABC"[i])) +d = {i: list(eval(input())) for i in "abc"} +i = "a" +while d[i]: +    i = d[i].pop(0) +print((i.upper()))