main = do
    a <- getLine
    b <- getLine
    c <- getLine
    putChar $ game a b c 'a'
    putStrLn ""

game [] _ _ 'a' = 'A'
game (a:as) bs cs 'a' = game as bs cs a
game _ [] _ 'b' = 'B'
game as (b:bs) cs 'b' = game as bs cs b
game _ _ [] 'c' = 'C'
game as bs (c:cs) 'c' = game as bs cs c