import Data.List parse :: String -> [(Int, Int)] parse = map ((\xs -> (xs !! 0, xs !! 1)) . map read . words) . lines process :: [(Int, Int)] -> [Char] process = map fst . sortBy (\(_, (x1, x2)) (_, (y1, y2)) -> compare y1 x1 `mappend` compare x2 y2) . zip ['A'..] output :: [Char] -> IO () output = mapM_ (putStrLn . (:[])) main :: IO () main = getContents >>= output . process . parse