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

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var n = cin.ReadInt;
            var Cards = new Card[n];
            for(int i = 0; i < n; i++) {
                Cards[i] = new Card(cin.ReadStrArray(2));
            }
            var CarbonCopy = new Card[n];
            Array.Copy(Cards, CarbonCopy, n);
            QuickSort(Cards, 0, n - 1);
            MergeSort(CarbonCopy);
            bool wasStable = Cards.Zip(CarbonCopy, (c1, c2) => new Tuple<Card, Card>(c1, c2)).All(C => C.Item1.Equals(C.Item2));
            Console.WriteLine(wasStable ? "Stable" : "Not stable");
            Console.WriteLine(Cards.Join("\n"));
        }
        int Partition<T>(T[] A, int p, int r) where T : IComparable<T> {
            var x = A[r];
            var i = p - 1;
            for(int j = p; j < r; j++) {
                if(A[j].CompareTo(x) <= 0) {
                    A.Swap(++i, j);
                }
            }
            A.Swap(i + 1, r);
            return i + 1;
        }
        void QuickSort<T>(T[] A, int p, int r) where T : IComparable<T> {
            if(p < r) {
                var q = Partition(A, p, r);
                QuickSort(A, p, q - 1);
                QuickSort(A, q + 1, r);
            }
        }
        void MergeSort<T>(T[] A, int left, int right) where T : IComparable<T> {
            if(left + 1 < right) {
                var mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }
        void Merge<T>(T[] A, int left, int mid, int right) where T : IComparable<T> {
            var nl = mid - left;
            var nr = right - mid;
            var L = new T[nl];
            var R = new T[nr];
            for(int i = 0; i < nl; i++)
                L[i] = A[i + left];
            for(int i = 0; i < nr; i++)
                R[i] = A[i + mid];
            int il = 0, ir = 0;
            for(int k = left; k < right; k++) {
                if(L[il].CompareTo(R[ir]) <= 0) {
                    A[k] = L[il++];
                    if(il == nl) {
                        k++;
                        for(; ir < nr;)
                            A[k++] = R[ir++];
                        break;
                    }
                }
                else {
                    A[k] = R[ir++];
                    if(ir == nr) {
                        k++;
                        for(; il < nl;)
                            A[k++] = L[il++];
                        break;
                    }
                }
            }
        }
        public void MergeSort<T>(T[] A) where T : IComparable<T> {
            MergeSort(A, 0, A.Length);
        }
        struct Card: IComparable<Card> {
            char suit { get; set; }
            int value { get; set; }
            public Card(string[] info) {
                suit = info[0][0];
                value = int.Parse(info[1]);
            }
            public int CompareTo(Card y) => value.CompareTo(y.value);
            public bool Equals(Card y) => suit == y.suit && value == y.value;
            public override string ToString() => suit.ToString() + " " + value.ToString();
        }
    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}



Measured memory_bytes: 31364