main = sol . words <$> getContents >>= putStrLn

sol [a,b,c] = f 'a' a b c

f 'a' [] _ _ = "A"
f 'b' _ [] _ = "B"
f 'c' _ _ [] = "C"
f 'a' (x:a) b c =  f x a b c
f 'b' a (x:b) c =  f x a b c
f 'c' a b (x:c) =  f x a b c