import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

read' :: B.ByteString -> Int
read' bs | Just (n, _) <- B.readInt bs = n

quicksort :: Ord b => (a -> b) -> [a] -> [a]
quicksort _ []     = []
quicksort _ [x]    = [x]
quicksort f (x:xs) = quicksort f ls ++ [x] ++ quicksort f rs
  where
    y = f x
    ls = filter ((<= y) . f) xs
    rs = filter ((> y)  . f) xs

print' :: (B.ByteString, Int) -> IO ()
print' (s, n) = putStrLn $ B.unpack s ++ " " ++ show n

main :: IO ()
main = do
    B.getLine
    let f [s, n] = (s, read' n)
    cs <- fmap (f . B.words) . B.lines <$> B.getContents
    let ds = quicksort snd cs
    if cs == ds
        then putStrLn "Stable"
        else putStrLn "Not Stable"
    mapM_ print' ds

