import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  s <- lines <$> getContents
  putChar $ game s 'a'

game ["",_,_] 'a' = 'A'
game [_,"",_] 'b' = 'B'
game [_,_,""] 'c' = 'C'
game [sa,sb,sc] turn
  |turn=='a' = game [(tail sa),sb,sc] (head sa)
  |turn=='b' = game [sa,(tail sb),sc] (head sb)
  |turn=='c' = game [sa,sb,(tail sc)] (head sc)