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


namespace AOJ_problem_01
{

    struct Card
    {
        public char alf;
        public int number;
    }

    class Program
    {
        static int n;
        static Card[] L;
        static Card[] R;
        const int Inf = 1 << 21;

        static void Merge(Card[] a, int left, int mid, int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;
            
            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].number = Inf;
            R[n2].number = Inf;

            int s = 0;
            int t = 0;

            for(int k = left; k < right; k++)
            {
                if(L[s].number <= R[t].number)
                {
                    a[k] = L[s++];                   
                }

                else
                {
                    a[k] = R[t++];
                }
            }
        }


        static void MergeSort(Card[] a, int n, int left, int right)
        {
            int mid;
            if(right - left > 1)
            {
                mid = (right + left) / 2;
                MergeSort(a, n, left, mid);
                MergeSort(a, n, mid, right);
                Merge(a, left, mid, right);
            }
        }

        static int mid;

        static int Partition(Card[] a, int p, int r)
        {
            int j = 0;
            int i = p - 1;
            Card v;
           
            for(j = p; j < r; j++)
            {              
                if(a[j].number <= a[r].number)
                {
                    i++;
                    v = a[i];
                    a[i] = a[j];
                    a[j] = v;                  
                }               
            }

            v = a[r];
            a[r] = a[i + 1];
            a[i + 1] = v;

            return ++i;
        }


        static void QuickSort(Card[] a, int n, int left, int right)
        {     
            if(left < right)
            {
                mid = Partition(a, left, right);
                QuickSort(a, n, left, mid - 1);
                QuickSort(a, n, mid + 1, right);
            }
        }

      
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());

            Card[] dataquick = new Card[n];
            Card[] datamerg = new Card[n];
            L = new Card[n];
            R = new Card[n];
            bool isstable = true;
;
            for(int i = 0; i < n; i++)
            {
                string str = Console.ReadLine();
                string[] strer = str.Split(' ');                          
                dataquick[i].alf = datamerg[i].alf = strer[0].ToCharArray()[0];
                dataquick[i].number = datamerg[i].number = int.Parse(strer[1].ToString());              
            }

            mid = 0;

            MergeSort(datamerg, n, 0, n);
            QuickSort(dataquick, n, 0, n-1);

            for(int i = 0; i < n; i++)
            {
                if(datamerg[i].alf != dataquick[i].alf)
                {
                    isstable = false;
                    break;
                }
            }

            if (isstable)
            {
                Console.WriteLine("Stable");
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine($"{dataquick[i].alf} {dataquick[i].number}");
                }
            }
            else
            {
                Console.WriteLine("Not stable");
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine($"{dataquick[i].alf} {dataquick[i].number}");
                }
            }

        }

    }

}




Measured memory_bytes: 22672