import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        implicit val ord = Ordering.by((e: (String, Long)) => e._2);
        val n = readInt;
        val arr1 = new Array[Card](n);
        val arr2 = new Array[Card](n);
        (0 until n).foreach { i => 
            val input = readLine.split(" ");
            val elem = Card(input(0), input(1).toInt);
            arr1(i) = elem;
            arr2(i) = elem;
        }
        quickSort(arr1, n);
        mergeSort(arr2, n);
        
        if ((0 until n).exists( i => arr1(i) != arr2(i))) println("Not stable") else println("Stable");
        println(arr1.mkString("\n"));
    }
    
    def quickSort(arr: Array[Card], n: Int): Unit = {
        def _quickSort(first: Int, last: Int): Unit = {
            if (first < last){
                val (pivot, needsPartition) = partition(first, last);
                if (needsPartition) {
                    _quickSort(first, pivot - 1);
                    _quickSort(pivot + 1, last);
                }
            }
        }
        def partition(first: Int, last: Int): (Int, Boolean) = {
            val pivot = arr(last);
            def _partition(sep: Int, ptr: Int, flag: Boolean): (Int, Boolean) = {
                if (ptr > last) {
                    (sep, flag);
                } else if (arr(ptr) > pivot) {
                    _partition(sep, ptr + 1, true);
                }else if (arr(ptr) < pivot) {
                    swap(arr, sep + 1, ptr);
                    _partition(sep + 1, ptr + 1, true);
                } else {
                    swap(arr, sep + 1, ptr);
                    _partition(sep + 1, ptr + 1, flag);
                }
            }
            _partition(-1, 0, false);
        }
        _quickSort(0, n - 1);
    }
    


    private def swap(arr: Array[Card], a: Int, b: Int): Unit = {
        val tmp = arr(a);
        arr(a) = arr(b);
        arr(b) = tmp;
    }
    
    def mergeSort(arr: Array[Card], n: Int): Unit = {
        def _mergeSort(first: Int, last: Int): Unit = {
            if (first < last) {
                val pivot = (first + last) / 2;
                val cnt1 = _mergeSort(first, pivot);
                val cnt2 = _mergeSort(pivot + 1, last);
                merge(first, last, pivot);
            }
        }
        def merge(first: Int, last: Int, pivot: Int): Unit = {
            val tmpArr = arr.slice(first, pivot + 1);
            var ptr1 = 0;
            var ptr2 = pivot + 1;
            for (i <- (first to last)) {
                if (ptr1 >= tmpArr.length) {
                    ptr2 += 1;
                } else if (ptr2 > last || tmpArr(ptr1) <= arr(ptr2)) {
                    arr(i) = tmpArr(ptr1);
                    ptr1 += 1;
                } else {
                    arr(i) = arr(ptr2);
                    ptr2 += 1;
                }
            }
        }
        
        _mergeSort(0, n - 1);
    }
}
case class Card(symbol: String, num: Int) {
    override def toString(): String = symbol + " " + num
    def <(a: Card): Boolean = this.num < a.num
    def <=(a: Card): Boolean = this.num <= a.num
    def >(a: Card): Boolean =  this.num > a.num
    def >=(a: Card): Boolean =  this.num >= a.num
}
