import Prelude hiding (flip)
import Control.Monad.State
import Data.List.Split
type Cups = (Bool,Bool,Bool)

main = do
    points <- fmap (map (splitOn ",").lines) getContents
    let actions = map makeAction points
        position = evalState (foldl1 (>>) actions) (True,False,False)

    putStrLn $ ballPosition position

getBall "A" (a,b,c) = a
getBall "B" (a,b,c) = b
getBall "C" (a,b,c) = c
setBall "A" i (a,b,c) = (i,b,c)
setBall "B" i (a,b,c) = (a,i,c)
setBall "C" i (a,b,c) = (a,b,i)

ballPosition :: Cups -> String
ballPosition (a,b,c)
    | a = "A"
    | b = "B"
    | c = "C"

makeAction [x,y] = flip x y
flip :: String -> String -> State Cups Cups
flip p1 p2 = do
    cups <- get
    let b1 = getBall p1 cups
        b2 = getBall p2 cups
        new = (setBall p1 b2).(setBall p2 b1) $ cups
    put new 
    return new