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

class Program
{
    public void Proc()
    {
        int num = int.Parse(Console.ReadLine());
        // string[] inpt = Console.ReadLine().Split(' ');
        // inpt = "D 3;H 2;D 1;S 3;D 2;C 1".Split(';');
        Dictionary<int, List<string>> dic = new Dictionary<int, List<string>>();
        InputItem[] arr = new InputItem[num];
        for (int i = 0; i < num; i++)
        {
            // arr[i] = new InputItem(inpt[i]);
            arr[i] = new InputItem(Console.ReadLine());
            if (!dic.ContainsKey(arr[i].IntValue))
            {
                dic.Add(arr[i].IntValue, new List<string>());
            }
            dic[arr[i].IntValue].Add(arr[i].Prefix);
        }
        this.QuickSort(arr, 0, arr.Length - 1);
        StringBuilder ans = new StringBuilder();
        int idx = 0;
        bool isStable = true;
        for (int i = 0; i < arr.Length; i++)
        {
            if (ans.Length > 0)
            {
                // ans.Append(" ");
                if (isStable)
                {
                    if (arr[i - 1].IntValue == arr[i].IntValue)
                    {
                        List<string> tmp = dic[arr[i].IntValue];
                        string prefix0 = arr[i - 1].Prefix;
                        string prefix1 = arr[i].Prefix;
                        if (tmp[idx].Equals(prefix0) && tmp[idx + 1].Equals(prefix1))
                        {

                        }
                        else
                        {
                            isStable = false;
                        }
                        idx++;
                    }
                    else
                    {
                        idx = 0;
                    }
                }
            }
            ans.AppendLine(arr[i].ToString());
        }
        Console.WriteLine(isStable ? "Stable" : "Not stable");
        Console.Write(ans.ToString());
    }

    public class InputItem
    {
        public int IntValue = 0;
        public String Prefix = string.Empty;
        public InputItem(string text)
        {
            this.Prefix = text.Substring(0, 1);
            this.IntValue = int.Parse(text.Substring(1).Trim());
        }
        public override string ToString()
        {
            return this.Prefix + " " + this.IntValue;
        }

        public static void Replace(InputItem item1, InputItem item2)
        {
            string pre = item1.Prefix;
            int intVal = item1.IntValue;

            item1.IntValue = item2.IntValue;
            item1.Prefix = item2.Prefix;
            item2.Prefix = pre;
            item2.IntValue = intVal;
        }
    }
    private void QuickSort(InputItem[] A, int p, int r)
    {
        /*
         * 1 quicksort(A, p, r)
            2   if p < r
            3     q = partition(A, p, r)
            4     quickSort(A, p, q-1)
            5     quickSort(A, q+1, r)
         * **/
        if (p < r)
        {
            int q = this.Partition(A, p, r);
            this.QuickSort(A, p, q - 1);
            this.QuickSort(A, q + 1, r);
        }

    }

    private int Partition(InputItem[] A, int p, int r)
    {
        /*
         * 1 partition(A, p, r)
            2   x = A[r]
            3   i = p-1
            4   for j = p to r-1
            4     if A[j] <= x
            5       i = i+1
            6       A[i] ??¨ A[j] ?????????
            7   A[i+1] ??¨ A[r] ?????????
            8   return i+1
         **/

        int x = A[r].IntValue;
        int i = p - 1;
        for (int j = p; j <= r - 1; j++)
        {
            if (A[j].IntValue <= x)
            {
                i++;
                InputItem.Replace(A[i], A[j]);
            }
        }
        InputItem.Replace(A[i + 1], A[r]);
        return i + 1;
    }


    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 28672