solve [] _ _ c = c
solve _ [] _ c = c
solve _ _ [] c = c
solve (c:cs) sb sc 'A' = case c of
                           'a' -> solve cs sb sc 'A'
                           'b' -> solve cs sb sc 'B'
                           'c' -> solve cs sb sc 'C'
solve sa (c:cs) sc 'B' = case c of
                           'a' -> solve sa cs sc 'A'
                           'b' -> solve sa cs sc 'B'
                           'c' -> solve sa cs sc 'C'
solve sa sb (c:cs) 'C' = case c of
                           'a' -> solve sa sb cs 'A'
                           'b' -> solve sa sb cs 'B'
                           'c' -> solve sa sb cs 'C'

main = do
  sa <- getLine
  sb <- getLine
  sc <- getLine
  putStrLn $ show $ solve sa sb sc 'A'
