using System;
using System.IO;

namespace Sort_II
{
    class Quick_Sort
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var A = new Card[n];
            var B = new Card[n];
            for (int i = 0; i < n; i++)
            {
                var token = Console.ReadLine().Split(' ');
                A[i] = B[i] = new Card(token[0][0], int.Parse(token[1]));
            }
            var p = 0;
            var r = A.Length - 1;

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            QuickSort(A, p, r);
            MergeSort(B, p, r + 1);

            if (IsStable(A, B)) Console.WriteLine("Stable");
            else Console.WriteLine("Not stable");

            for (int i = 0; i < r; i++)
                Console.WriteLine(A[i]);
            Console.WriteLine(A[r]);

            Console.Out.Flush();
        }

        static bool IsStable(Card[] A, Card[] B)
        {
            var f = true;
            for (int i = 0; i < A.Length; i++)
            {
                if (!A[i].Equals(B[i])) f = false;
            }
            return f;
        }

        static public void QuickSort(Card[] A, int p, int r)
        {
            if (p < r)
            {
                var q = Partition(A, p, r);
                QuickSort(A, p, q - 1);
                QuickSort(A, q + 1, r);
            }
        }

        static public int Partition(Card[] A, int p, int r)
        {
            var x = A[r].rank;
            var i = p - 1;
            for (int j = p; j < r; j++)
                if (A[j].rank <= x)
                {
                    i++;
                    var temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            var tmp = A[i + 1];
            A[i + 1] = A[r];
            A[r] = tmp;

            return i + 1;
        }

        public struct Card
        {
            public int rank;
            char suit;
            public Card(char c, int r)
            {
                rank = r; suit = c;
            }
            public override string ToString()
            {
                return suit + " " + rank;
            }
        }

        static void Merge(Card[] A, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;
            var L = new Card[n1 + 1];
            var R = new Card[n2 + 1];
            for (int i = 0; i < n1; i++)
                L[i] = A[left + i];
            for (int i = 0; i < n2; i++)
                R[i] = A[mid + i];
            L[n1] = R[n2] = new Card('s', int.MaxValue);
            var p = 0; var q = 0;
            for (int k = left; k < right; k++)
                if (L[p].rank <= R[q].rank) A[k] = L[p++];
                else A[k] = R[q++];
        }

        static void MergeSort(Card[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }
    }
}

Measured memory_bytes: 13092