main = putStrLn . solve . lines =<< getContents

solve [as,bs,cs] =
    let f 'a' as' bs' cs'
            | null as' = "A"
            | otherwise = f (head as') (tail as') bs' cs'
        f 'b' as' bs' cs'
            | null bs' = "B"
            | otherwise = f (head bs') as' (tail bs') cs'
        f 'c' as' bs' cs'
            | null cs' = "C"
            | otherwise = f (head cs') as' bs' (tail cs')
    in f 'a' as bs cs
