import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Array.IO
import Data.List (group)

data Card = C String Int

instance Eq Card where
        (C s1 i1) == (C s2 i2) = i1 == i2
instance Ord Card where
        compare (C s1 i1) (C s2 i2) = compare i1 i2

readCard :: [String] -> Card
readCard [s,n] = C s (read n)

printCard :: Card -> IO ()
printCard (C s i) = putStrLn $ s ++ " " ++ show i

showcard (C s i) = show s ++ " " ++ show i

main = do
        n <- readLn
        list <- replicateM n (readCard.words<$>getLine)
        arr <- newListArray (0,(n-1)) list
        quickSort arr 0 (n-1)
        list' <- getElems arr
        let listg = group list'
        if checkStable list listg then putStrLn "Stable" >> mapM_ printCard list'
                                  else putStrLn "Not stable" >> mapM_ printCard list'


quickSort :: IOArray Int Card -> Int -> Int -> IO (IOArray Int Card)
quickSort arr p r | p >= r = return arr
                  | otherwise = do
                      q <- partition p r arr
                      quickSort arr p (q-1)
                      quickSort arr (q+1) r

partition :: Int -> Int -> IOArray Int Card -> IO Int
partition p r arr = evalStateT (part p r arr) (p-1)

part :: Int -> Int -> IOArray Int Card -> StateT Int IO Int
part p r arr = do
        x <- liftIO $ readArray arr r
        forM_ [p..(r-1)] $ \j -> do
            e <- liftIO $ readArray arr j
            if e <= x then modify (+1) >> get >>= \i' -> (liftIO $ swap arr i' j)
                      else return ()
        i <- get
        liftIO $ swap arr (i+1) r
        return (i+1)

swap :: IOArray Int Card -> Int -> Int -> IO ()
swap arr i j = do
        eI <- readArray arr i
        eJ <- readArray arr j
        writeArray arr j eI
        writeArray arr i eJ

checkStable orgn [] = True
checkStable orgn (s:ss)
    | length s == 1 = checkStable orgn ss
    | otherwise     = if check orgn s then checkStable orgn ss
                                      else False

check orgn ss = all id $ zipWith compareCard orgn' ss
    where s = head ss
          orgn' = filter (\c -> num c == num s) orgn
          num (C _ i) = i
          compareCard (C s1 i1) (C s2 i2) = s1 == s2 && i1 == i2