main = getContents >>= putStrLn . solve 'a' . words

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