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

solve :: String -> String -> String -> Char -> Char
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
