import Data.Maybe (fromJust)
import Data.List (elemIndex, sort)
import Data.List.Split (splitOn)

swapCups [o1, o2] [a, b, c]
    | o1 == "A" && o2 == "B" = [b, a, c]
    | o1 == "A" && o2 == "C" = [c, b, a]
    | o1 == "B" && o2 == "C" = [a, c, b]

findBall cs
    | i == 0 = "A"
    | i == 1 = "B"
    | i == 2 = "C"
        where i = fromJust $ elemIndex 1 cs

main :: IO ()
main = putStrLn . findBall . foldr swapCups [1, 0, 0] . map sort . map (splitOn ",") . lines =<< getContents