import Control.Applicative
import Control.Monad
import Data.List

solve :: String -> String -> String -> String
solve as bs cs = iter 'a' as bs cs
  where
    iter 'a' xs ys zs
        | null xs   = "A"
        | otherwise = iter (head xs) (tail xs) ys zs
    iter 'b' xs ys zs
        | null ys   = "B"
        | otherwise = iter (head ys) xs (tail ys) zs
    iter 'c' xs ys zs
        | null zs   = "C"
        | otherwise = iter (head zs) xs ys (tail zs)

main :: IO ()
main = do
    as <- getLine
    bs <- getLine
    cs <- getLine
    putStrLn $ solve as bs cs