solve :: [(Char, Char)] -> Char
solve = foldl f 'A'
  where f c (a, b) | a == c    = b
                   | b == c    = a
                   | otherwise = c

main :: IO ()
main = getContents >>= putStrLn . return . solve . input
  where input = map tup . lines
        tup (a:',':b:_) = (a, b)