main = do
 sa<-getLine
 sb<-getLine
 sc<-getLine
 putStrLn $ f sa sb sc 'a'
 
f [] y z 'a' = "A"
f x [] z 'b' = "B"
f x y [] 'c' = "C"
f (x:xs) y z 'a' = f xs y z x
f x (y:ys) z 'b' = f x ys z y
f x y (z:zs) 'c' = f x y zs z
