import Control.Monad

calc 'a' ["", _, _] = "A"
calc 'a' [a:as, bs, cs] = calc a [as, bs, cs]
calc 'b' [_, "", _] = "B"
calc 'b' [as, b:bs, cs] = calc b [as, bs, cs]
calc 'c' [_, _, ""] = "C"
calc 'c' [as, bs, c:cs] = calc c [as, bs, cs]

main = replicateM 3 getLine >>= putStrLn . calc 'a'