import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine <*> getLine <*> getLine >>= putStrLn

solve :: String -> String -> String -> String
solve sa sb sc = f 'a' sa sb sc
  where
    f x as bs cs
      | x == 'a' && null as = "A"
      | x == 'a' = f (head as) (tail as) bs cs
      | x == 'b' && null bs = "B"
      | x == 'b' = f (head bs) as (tail bs) cs
      | x == 'c' && null cs = "C"
      | otherwise = f (head cs) as bs (tail cs)
