import Data.List
import Control.Monad

main = do
  [sa, sb, sc] <- replicateM 3 getLine
  putStrLn $ solve 'a' (sa, sb, sc)

solve 'a' ([], _, _) = "A"
solve 'b' (_, [], _) = "B"
solve 'c' (_, _, []) = "C"
solve 'a' (x:xs, sb, sc) = solve x (xs, sb, sc)
solve 'b' (sa, x:xs, sc) = solve x (sa, xs, sc)
solve 'c' (sa, sb, x:xs) = solve x (sa, sb, xs)