import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 文字列の入力
    sa <- getLine
    sb <- getLine
    sc <- getLine
    -- 出力
    putStrLn $ solve sa sb sc "A"

solve :: String -> String -> String -> String -> String
solve [] _ _ "A" = "A"
solve _ [] _ "B" = "B"
solve _ _ [] "C" = "C"
solve sa sb sc "A" = solve (drop 1 sa) sb sc (take 1 sa)
solve sa sb sc "B" = solve sa (drop 1 sb) sc (take 1 sb)
solve sa sb sc "C" = solve sa sb (drop 1 sc) (take 1 sc)
