winner 'a' [] _ _ = "A"
winner 'b' _ [] _ = "B"
winner 'c' _ _ [] = "C"
winner 'a' (a:as) bs cs = winner a as bs cs
winner 'b' as (b:bs) cs = winner b as bs cs
winner 'c' as bs (c:cs) = winner c as bs cs

main = do
    sa <- getLine
    sb <- getLine
    sc <- getLine
    putStrLn $ winner (head sa) (tail sa) sb sc
