{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
-- {-# LANGUAGE MultiWayIf #-}
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ViewPatterns #-}
-- {-# LANGUAGE TupleSections #-}

import           System.IO hiding (char8)
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Tuple
import           Data.Int
import           Data.Char
import           Data.Function (on)
import           Data.Ord (comparing)
import           Data.Monoid (mappend)
import           Data.Array
import           Data.Array.Unboxed
-- import           Data.Array.IArray
-- import           Data.Array.ST
import           Data.Array.MArray
-- import           Data.Array.Unsafe
import           Data.Array.Base(unsafeRead, unsafeWrite)
import           Data.Array.IO
import           Data.Ix
import           Data.Maybe
-- import           Data.Monoid hiding ((<>))
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import           Data.ByteString.Builder
-- import           Data.Graph
-- import           Data.Vector.Unboxed ((//), (++), (!), (!?))
-- import qualified Data.Vector.Unboxed as U
-- import           Data.IntSet (IntSet)
-- import qualified Data.IntSet as IntSet
-- import           Data.IntMap.Strict (IntMap)
-- import qualified Data.IntMap.Strict as IntMap
-- import           Data.Sequence ((|>), (<|), (><),ViewR(..), ViewL(..), Seq)
-- import qualified Data.Sequence              as Seq
-- import           Data.Foldable (toList, minimumBy)
-- import           Debug.Trace

type Card = (Char, Int, Int)

main :: IO ()
main = do
  n <- readInt1 <$> BS.getLine
  ns <- map (applyTuple BS.head readInt1 . toTuple . BS.words) <$> replicateM n BS.getLine
  let (a,b) = unzip ((' ',0):ns)
  let ns' = zip3 a b [0..]
  arr <- newListArray (0, n) ns' :: IO (IOArray Int Card)
  quicksort arr 1 n
  es <- tail <$> getElems arr
  putStrLn $ if stable es then "Stable" else "Not stable"
  mapM_ (putStrLn . (\(a, b, _) -> a:' ':show b)) es

quicksort :: (MArray a Card m) => a Int Card -> Int -> Int -> m ()
quicksort arr p r =
  when (p < r) $ do
    partition' arr p r
    (_, q, _) <- readArray arr 0
    quicksort arr p (q-1)
    quicksort arr (q+1) r


partition' :: (MArray a Card m) => a Int Card -> Int -> Int -> m ()
partition' arr p r = do
  (_, x, _) <- readArray arr r
  writeArray arr 0 (' ', p-1, 0)
  forM_ [p..r-1] $ \j -> do
    (_, y, _) <- readArray arr j
    when (y <= x) $ do
      increment arr
      (_, i, _) <- readArray arr 0
      swapArray arr i j
  (_, i, _) <- readArray arr 0
  swapArray arr (i+1) r
  writeArray arr 0 (' ', i+1, 0)

swapArray :: (MArray a e m) => a Int e -> Int -> Int -> m ()
swapArray arr i j = do
  x <- unsafeRead arr i
  y <- unsafeRead arr j
  unsafeWrite arr i y
  unsafeWrite arr j x

increment :: (MArray a Card m) => a Int Card -> m ()
increment arr = do
  (s, x, i) <- unsafeRead arr 0
  unsafeWrite arr 0 (s, x+1, i)

stable :: [Card] -> Bool
stable [_] = True
stable ((_, x, i):(s, y, j):xs) = not (x == y && i > j) && stable ((s, y, j):xs)

putInts' xs x = putStrLn . unwords . zipWith f [0..] $ map show xs where
  f i e = if i == x then "[" ++ e ++ "]" else e

--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

getInt1 :: IO Int
getInt1 = readInt1 <$> BS.getLine

getInt2 :: IO (Int, Int)
getInt2 = readInt2 <$> BS.getLine

getInt3 :: IO (Int, Int, Int)
getInt3 = readInt3 <$> BS.getLine

getInts :: IO [Int]
getInts = readInts <$> BS.getLine

getIntN :: Int -> IO [Int]
getIntN n = map readInt1 <$> replicateM n BS.getLine

format :: Show a => Maybe a -> IO ()
format Nothing = putStrLn "NO"
format (Just a) = putStrLn "YES" >> print a

-- [1,2,3] -> 1 2 3
putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt

readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readInts

readInt3 :: BS.ByteString -> (Int,Int,Int)
readInt3 = toTriple . readInts

readInts :: BS.ByteString -> [Int]
readInts =  map readInt1 . BS.words

readInt641 :: BS.ByteString -> Int64
readInt641 = fromIntegral . fst . fromJust . BS.readInteger

readInt642 :: BS.ByteString -> (Int64,Int64)
readInt642 = toTuple . readInt64s

readInt643 :: BS.ByteString -> (Int64,Int64,Int64)
readInt643 = toTriple . readInt64s

readInt64s :: BS.ByteString -> [Int64]
readInt64s =  map readInt641 . BS.words

readInteger1 :: BS.ByteString -> Integer
readInteger1 = fst . fromJust . BS.readInteger

readInteger2 :: BS.ByteString -> (Integer,Integer)
readInteger2 = toTuple . readIntegers

readInteger3 :: BS.ByteString -> (Integer,Integer,Integer)
readInteger3 = toTriple . readIntegers

readIntegers :: BS.ByteString -> [Integer]
readIntegers =  map readInteger1 . BS.words

toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

toTriple :: [a] -> (a, a, a)
toTriple [x, y, z] =(x, y, z)

fromTuple :: (a, a) -> [a]
fromTuple (x, y) = [x, y]

fromTriple :: (a, a, a) -> [a]
fromTriple (x, y, z) = [x, y, z]

-- if not applying, use "const"

applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
applyTuple f g (x, y) = (f x, g y)

applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c')
applyTriple f g h (x, y, z) = (f x, g y, h z)

-- @since 4.8.0.0
sortOn' :: Ord b => (a -> b) -> [a] -> [a]
sortOn' f =
  map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))

Measured memory_bytes: 44008