import           Control.Monad
import           Data.Char

main :: IO ()
main = do
  [a, b, c] <- replicateM 3 getLine
  putStrLn $ solve 'a' [a, b, c]

solve :: Char -> [String] -> String
solve p (a : b : c : _) | a == "" && p == 'a' = "A"
                        | b == "" && p == 'b' = "B"
                        | c == "" && p == 'c' = "C"
                        | p == 'a'            = solve (last a) [init a, b, c]
                        | p == 'b'            = solve (last b) [a, init b, c]
                        | p == 'c'            = solve (last c) [a, b, init c]

