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[(String, Long)](n);
        val arr2 = new Array[(String, Long)](n);
        (0 until n).foreach { i => 
            val input = readLine.split(" ");
            val elem = (input(0), input(1).toLong);
            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.map(e => e._1 + " " + e._2).mkString("\n"));
    }
    
        def quickSort(arr: Array[(String, Long)], n: Int): 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);
    }
    
    private def partition(arr: Array[(String, Long)], first: Int, last: Int): Int = {
        val pivot = arr(last)._2;
        def _partition(ptr: Int, sep: Int): Int = {
            if (ptr > last) {
                sep;
            } else if (arr(ptr)._2 > pivot) {
                _partition(ptr + 1,  sep);
            } else {
                swap(arr, ptr, sep + 1);
                _partition(ptr + 1, sep + 1);
            }
        }
        _partition(0, -1);
    }

    private def swap(arr: Array[(String, Long)], a: Int, b: Int): Unit = {
        val tmp = arr(a);
        arr(a) = arr(b);
        arr(b) = tmp;
    }
    
    def mergeSort(arr: Array[(String, Long)], 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(arr, first, last, pivot);
            }
        }
        _mergeSort(0, n - 1);
    }
    
    private def merge(arr: Array[(String, Long)], 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) {
                arr(i) = arr(ptr2);
                ptr2 += 1;
            } else if (ptr2 > last) {
                arr(i) = tmpArr(ptr1);
                ptr1 += 1;
            } else {
                if (arr(ptr2)._2 < tmpArr(ptr1)._2) {
                    arr(i) = arr(ptr2);
                    ptr2 += 1;
                } else {
                    arr(i) = tmpArr(ptr1);
                    ptr1 += 1;
                }
            }
        }
    }
}
