import Data.Maybe
import Data.List

main = putStrLn . solve . lines =<< getContents

solve :: [String] -> String
solve = solve' 0 . map (map $ maybe 0 id . flip elemIndex ids)
    where
        ids = "abc"
        solve' 0 [[],_,_] = "A"
        solve' 1 [_,[],_] = "B"
        solve' 2 [_,_,[]] = "C"
        solve' 0 [(a:as),bs,cs] = solve' a [as,bs,cs]
        solve' 1 [as,(b:bs),cs] = solve' b [as,bs,cs]
        solve' 2 [as,bs,(c:cs)] = solve' c [as,bs,cs]
