using System;
using System.Collections.Generic;
					
public class my
{
	public static void Main()
	{
		var n = my.GetInt();
		var A = new Card[n];
		
		for(int i = 0; i < n; i++) {
			A[i] = new Card(Console.ReadLine());
		}
		
		Card[] B = new Card[n];
		A.CopyTo(B, 0);
		
		my.QuickSort(A, 0, n-1);
		my.MergeSort(B, 0, n);
		
		//stablity check
		bool isStable = true;
		for(int i = 0; i < A.Length; i++) {
			if(B[i].ToString() != A[i].ToString()){
				isStable = false;
				break;
			}
		}
		
		Console.WriteLine(isStable? "Stable" : "Not stable");
		for(int i = 0; i < n; i++) {
			Console.WriteLine(A[i].ToString());
		}
	}
	
	public static void BubbleSort(Card[] A)
	{
		bool flag = true;
		
		while(flag) {
			flag = false;
			
			for(int i = A.Length -1; i > 0; i--) {
				if(A[i-1].CompareTo(A[i]) > 0) { 
					Card.Swap(ref A[i], ref A[i-1]);
					flag = true;
				}
			}
		}
	}
	
	private static void QuickSort(Card[] A, int p, int r)
	{
		if(p < r) {
			var q = my.Partition(A, p, r);
			my.QuickSort(A, p, q-1);
			my.QuickSort(A, q+1, r);
		}
	}
	
	private static int Partition(Card[] A, int p, int r)
	{
		var x = A[r];
		var i = p-1;
		
		for(int j = p; j < r; j++) {
			if(A[j].CompareTo(x)  <= 0) {
				Card.Swap(A, ++i, j);
			}
		}
		Card.Swap(A, i+1, r);
		
		return i+1;	// pivot index
	}
	
	private static int Partition(int[] A, int p, int r)
	{
		var x = A[r];
		var i = p-1;
		
		for(int j = p; j < r; j++) {
			if(A[j] <= x) {
				my.Swap(A, ++i, j);
			}
		}
		my.Swap(A, i+1, r);
		
		return i+1;	// pivot index
	}
	
	private static void MergeSort(Card[] A, int left, int right)
	{
		if(left +1 < right) {
			int mid = (left + right) / 2;
			
			my.MergeSort(A, left, mid);
			my.MergeSort(A, mid, right);
			my.Merge(A, left, mid, right);
		}
	}
	
	private 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];
		Array.Copy(A, left, L, 0, n1);
		var R = new Card[n2 + 1];	// for sentinel
		Array.Copy(A, mid, R, 0, n2);
		L[n1] = new Card(int.MaxValue);
		R[n2] = new Card(int.MaxValue);
		
		int i = 0, j=0;
		
		for(int k = left; k < right; k++) {
			if(L[i].CompareTo(R[j]) <= 0) {
				A[k] = L[i++];
			} else {
				A[k] = R[j++];
			}
		}
	}
	
	private static void Swap(int[] A, int i, int j)
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine(string.Format("{0:f8} {1:f8}", v.X, v.Y));
	}
}

public struct Vector
{
	public double X,Y;
}

public class Card
{
	public int Number { get; private set; }
	public char Suit { get; private set; }
	
	public Card(string s)
	{
		this.Suit = s[0];
		this.Number = int.Parse(s.Substring(2));
	}
	
	public Card(int n)
	{
		this.Suit = '*';
		this.Number = n;
	}
	
	public int CompareTo(Card c)
	{
		return this.Number - c.Number;
	}
	
	public override string ToString()
	{
		return Suit.ToString() + " " + Number.ToString();
	}
	
	public static void Swap(ref Card a, ref Card b)
	{
		Card tmp;
		tmp = a;
		a = b;
		b = tmp;
	}
	
	public static void Swap(Card[] A, int i, int j)
	{
		Card tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
}

Measured memory_bytes: 16464