import Data.List

main = interact $ cup_game . map (splitOn ',') . lines
cup_game = foldl' swap "A"
 where swap c [c1,c2] | c == c1 = c2 | c == c2 = c1 | otherwise = c

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)