solver::([Char],[Char],[Char])->Char->String
solver ([],_,_) 'a'= "A"
solver (_,[],_) 'b'= "B"
solver (_,_,[]) 'c'= "C"
solver (a:as,bs,cs) 'a'= case a of
                    'a' -> solver (as,bs,cs) 'a'
                    'b' -> solver (as,bs,cs) 'b'
                    'c' -> solver (as,bs,cs) 'c'
solver (as,b:bs,cs) 'b'= case b of
                    'a' -> solver (as,bs,cs) 'a'
                    'b' -> solver (as,bs,cs) 'b'
                    'c' -> solver (as,bs,cs) 'c'
solver (as,bs,c:cs) 'c'= case c of
                    'a' -> solver (as,bs,cs) 'a'
                    'b' -> solver (as,bs,cs) 'b'
                    'c' -> solver (as,bs,cs) 'c'

main::IO()
main =do
  as<-getLine
  bs<-getLine
  cs<-getLine
  putStr ((solver (as,bs,cs) 'a')++"\n")
