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

object Main {
    
    def main(args: Array[String]): Unit = {
        implicit val ord = Ordering.by((e: (String, Long)) => e._2);
        val n = readInt;
        val arr1 = (0 until n).map { i => 
            val Array(mark, num) = readLine.split(" ");
            (mark, num.toLong);
        }.toArray;
        val arr2 = new Array[(String, Long)](n);
        (0 until n).foreach { i => arr2(i) = arr1(i)};
        
        quickSort[(String, Long)](arr1, n);
        mergeSort[(String, Long)](arr2, n);
        
        if ((0 until n).exists( i => arr1(i) != arr2(i))) println("Not stable") else println("Stable");
        println(arr1.map(e => e._1 + " " + e._2).mkString("\n"));
    }
    
    def quickSort[A](arr: Array[A], n: Int)(implicit ord: Ordering[A]): Unit = {
        def _quickSort(first: Int, last: Int): Unit = {
            if (first < last){
                val pivot = partition(arr, first, last);
                _quickSort(first, pivot - 1);
                _quickSort(pivot + 1, last);
            }
        }
        _quickSort(0, n - 1);
    }
    
    def partition[A](arr: Array[A], first: Int, last: Int)(implicit ord: Ordering[A]): Int = {
        import ord._;
        val pivot = arr(last);
        def _partition(ptr: Int, laterPtr: Int): Int = {
            if (ptr > last) {
                laterPtr;
            } else {
                if (arr(ptr) > pivot) {
                    _partition(ptr + 1,  laterPtr);
                } else {
                    swap(arr, ptr, laterPtr + 1);
                    _partition(ptr + 1, laterPtr + 1);
                }
            }
        }
        _partition(0, -1);
    }

    private def swap[A](arr: Array[A], a: Int, b: Int): Unit = {
        val tmp = arr(a);
        arr(a) = arr(b);
        arr(b) = tmp;
    }
    
    def mergeSort[A](arr: Array[A], n: Int)(implicit ord: Ordering[A], m: ClassTag[A]): Int = {
        import ord._;
        def _mergeSort(first: Int, last: Int): Int = {
            if (last - first > 0) {
                val pivot = (first + last) / 2;
                val cnt1 = _mergeSort(first, pivot);
                val cnt2 = _mergeSort(pivot + 1, last);
                merge(arr, first, last, pivot);
                cnt1 + cnt2 + (last - first + 1);
            } else {
                0;
            }
        }
        _mergeSort(0, n - 1);
    }
    
    def merge[A](arr: Array[A], first: Int, last: Int, pivot: Int)(implicit ord: Ordering[A], m: ClassTag[A]): Unit = {
        import ord._;
        val tmpArr = (first to pivot).map(arr(_)).toArray;
        var ptr1 = 0;
        var ptr2 = pivot + 1;
        for (i <- (first to last)) {
            if (ptr1 >= tmpArr.length) {
                arr(i) = arr(ptr2);
                ptr2 += 1;
            } else if (ptr2 > last) {
                arr(i) = tmpArr(ptr1);
                ptr1 += 1;
            } else {
                if (arr(ptr2) < tmpArr(ptr1)) {
                    arr(i) = arr(ptr2);
                    ptr2 += 1;
                } else {
                    arr(i) = tmpArr(ptr1);
                    ptr1 += 1;
                }
            }
        }
    }
}
