import Control.Monad
import Data.List
main=do
    a<-getLine
    b<-getLine
    c<-getLine
    putStrLn $ ta a b c

ta [] _ _ = "A"
ta (a:ar) b c
    | a=='a' = ta ar b c
    | a=='b' = tb ar b c
    | a=='c' = tc ar b c

tb _ [] _ = "B"
tb a (b:br) c
    | b=='a' = ta a br c
    | b=='b' = tb a br c
    | b=='c' = tc a br c

tc _ _ [] = "C"
tc a b (c:cr)
    | c=='a' = ta a b cr
    | c=='b' = tb a b cr
    | c=='c' = tc a b cr
