using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_6_C_Quick_Sort
{
    public struct Card
    {
        public char suit;
        public int value;
    }
    public class Program
    {
        const int MAX = 100000;
        static int[] array = new int[MAX];
        const int INF = int.MaxValue;
        public static Card[] L = new Card[MAX / 2 + 2], R = new Card[MAX / 2 + 2];


        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var cards = new Card[MAX];
            var cards2 = new Card[MAX];
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                cards[i].suit = char.Parse(input[0]);
                cards[i].value = int.Parse(input[1]);
                cards2[i].suit = char.Parse(input[0]);
                cards2[i].value = int.Parse(input[1]);
            }
            QuickSort(cards, 0, n - 1);
            MergeSort(cards2, 0, n);
            bool stable = true;
            for (int i = 0; i < n; i++)
            {
                if(cards[i].suit != cards2[i].suit)
                {
                    stable = false;
                    break;
                }
            }

            if (stable)
            {
                Console.WriteLine("Stable");
            }
            else
            {
                Console.WriteLine("Not stable");
            }

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(cards[i].suit + " " + cards[i].value);
            }
        }

        static void QuickSort(Card[] array, int left, int right)
        {
            int q;
            if (left < right)
            {
                q = Partition(array, left, right);
                QuickSort(array, left, q - 1);
                QuickSort(array, q + 1, right);
            }
        }
        static int Partition(Card[] array, int left, int right)
        {
            var scanned = left; //走査完了の要素のインデックス
            var changeIndexLast = left; //走査済みのインデックスと入れ替え済みのインデックスは別物
            bool UpperSentinel = false; //sentinel="番兵"のこと
            for (int i = left; i < right; i++)
            {
                //まず番兵より大きい数がでてくるまでfor文を飛ばす。でてきたらそこから
                //番兵以下の数とそうでない数を分けていく
                if (!UpperSentinel)
                {
                    if (array[i].value > array[right].value) //今回の番兵は配列右端の要素の数のことを指す
                    {
                        UpperSentinel = true;
                        changeIndexLast = scanned;
                    }

                    if (array[i].value <= array[right].value)
                    {
                        scanned++;
                        continue;
                    }
                }

                //調査対象の要素が番兵以下だった時
                if (array[i].value <= array[right].value)
                {
                    scanned++;
                    if (i >= 1)
                    {
                        var d = array[changeIndexLast];
                        array[changeIndexLast] = array[i];
                        array[i] = d;
                        changeIndexLast++;
                    }
                }
            }

            var c = array[scanned];
            array[scanned] = array[right];
            array[right] = c;
            return scanned;
        }

        static void MergeSort(Card[] array, int left, int right)
        {
            if (left + 1 < right)
            {
                int mid = (left + right) / 2;
                MergeSort(array, left, mid);
                MergeSort(array, mid, right); //もっとも小さい配列に分解していく(要素数1まで)
                Merge(array, left, mid, right); //大小を比べて併合していく
            }
        }

        static void Merge(Card[] array, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;

            for (int i = 0; i < n1; i++)
            {
                L[i] = array[left + i];
            }
            for (int i = 0; i < n2; i++)
            {
                R[i] = array[mid + i];
            }
            L[n1].value = R[n2].value = INF;
            int o = 0;
            int p = 0;
            for (int k = left; k < right; k++)
            {
                if (L[o].value <= R[p].value)
                {
                    array[k] = L[o++];
                }
                else
                {
                    array[k] = R[p++];
                }
            }
        }


    }
}



Measured memory_bytes: 24324