/**
 * クイックソート
 */
fun main(args: Array<String>) {

    Main.init()

    Main.execute()

    Main.display()
}

class Main {

    companion object {

        private var outs = arrayListOf<Item>()

        fun init() {
            val size = readLine()!!.toInt()
            for (index in 1..size) {
                val input = readLine()!!.split(" ")
                outs.add(Item(input[0], input[1].toInt(), index))
            }
        }

        fun execute() {
            quickSort(outs, 0, outs.size - 1)
        }

        fun display() {

            // 安定かどうかをチェック
            var isStable = true

            for (index in 1 until outs.size) {
                val lastItem = outs[index - 1]
                val currentItem = outs[index]

                if (lastItem.key == outs[index].key) {
                    if (lastItem.originalIndex > currentItem.originalIndex) {
                        isStable = false
                        break
                    }
                }
            }

            println(if (isStable) "Stable" else "Not stable")

            outs.forEach {
                println(it.symbol + " " + it.key)
            }
        }


        /**
         * 配列をクイックソート
         */
        fun quickSort(list: ArrayList<Item>, startIndex: Int, endIndex: Int) {

            if (startIndex >= endIndex) {
                return
            }

            val lastItem = list[endIndex]

            var cursorBefore = startIndex
            var cursorAfter = startIndex

            while (cursorAfter != endIndex + 1) {
                val target = list[cursorAfter]

                if (target.key <= lastItem.key) {
                    swap(list, cursorAfter, cursorBefore)
                    cursorBefore++
                }

                cursorAfter++
            }

            quickSort(list, startIndex, cursorBefore - 2)
            quickSort(list, cursorBefore, endIndex)
        }

        fun swap(list: ArrayList<Item>, a: Int, b: Int): ArrayList<Item> {
            val temp = list[a]
            list[a] = list[b]
            list[b] = temp
            return list
        }
    }
}


data class Item(val symbol: String, val key: Int, val originalIndex: Int)



