import qualified Data.ByteString.Char8 as BS
import Data.Maybe

main :: IO ()
main = do
  ah <- BS.unpack <$> BS.getLine :: IO String
  bh <- BS.unpack <$> BS.getLine :: IO String
  ch <- BS.unpack <$> BS.getLine :: IO String
  let table = (P A ah, P B bh, P C ch)
  putStr $ game table A

type Hands = String 
type Card = Char
data Name = A | B | C deriving Show
data Player = P Name Hands deriving Show
type Table = (Player, Player, Player)

class Play p where
  nextCard :: p -> Maybe Card
  nextHands :: p -> Hands

instance Play Player where
  nextCard (P _ "") = Nothing
  nextCard (P _ (x:_)) = Just x
  nextHands (P _ "") = ""
  nextHands (P _ (_:xs)) = xs
  
showNext :: Maybe Char -> Name
showNext (Just 'a') = A
showNext (Just 'b') = B
showNext (Just 'c') = C

game :: Table -> Name -> String
game (a,b,c) A 
  | isNothing (nextCard a) = "A"
  | otherwise = game (P A hands, b, c) (showNext card)
    where card = nextCard a
          hands = nextHands a
game (a,b,c) B
  | isNothing (nextCard b) = "B"
  | otherwise = game (a, P B hands, c) (showNext card)
    where card = nextCard b
          hands = nextHands b
game (a,b,c) C
  | isNothing (nextCard c) = "C"
  | otherwise = game (a, b, P C hands) (showNext card)
    where card = nextCard c
          hands = nextHands c