main :: IO()
main = do
    astr <- getLine
    bstr <- getLine
    cstr <- getLine
    putStrLn $ [getsolve astr bstr cstr 'a']


getsolve :: String -> String -> String -> Char -> Char
getsolve astr bstr cstr 'a'
    | astr == []			= 'A'
    | otherwise				= getsolve (tail astr) bstr cstr (head astr)

getsolve astr bstr cstr 'b'
    | bstr == []			= 'B'
    | otherwise				= getsolve astr (tail bstr) cstr (head bstr)

getsolve astr bstr cstr 'c'
    | cstr == []			= 'C'
    | otherwise				= getsolve astr bstr (tail cstr) (head cstr)


