main = do
  as <- getLine
  bs <- getLine
  cs <- getLine
  putStrLn $ solve as bs cs 'a'

solve :: String -> String -> String -> Char -> String
solve [] _ _ 'a' = "A"
solve (x:xs) bs cs 'a' = solve xs bs cs x
solve _ [] _ 'b' = "B"
solve as (x:xs) cs 'b' = solve as xs cs x
solve _ _ [] 'c' = "C"
solve as bs (x:xs) 'c' = solve as bs xs x
