solve a b c t
    | t == 'a' && null a = "A"
    | t == 'b' && null b = "B"
    | t == 'c' && null c = "C"
    | t == 'a' = solve (tail a) b c (head a)
    | t == 'b' = solve a (tail b) c (head b)
    | t == 'c' = solve a b (tail c) (head c)

main = do
    a <- getLine
    b <- getLine
    c <- getLine
    putStrLn $ solve a b c (head a)