import Data.List
import Control.Monad
f a b c i = case i of 'a' -> if null a then "A" else f (tail a) b c (head a)
                      'b' -> if null b then "B" else f a (tail b) c (head b)
                      'c' -> if null c then "C" else f a b (tail c) (head c)
main=do
 [a,b,c]<-replicateM 3 getLine
 putStrLn$f a b c 'a'