#include<stdio.h>
#define N_MAX 100005

typedef struct card
{
	char mark;
	int num;
}Card;

Card A[N_MAX], bubble[N_MAX];

void BubbleSort(Card *A, int n){
	int i, j;
	Card work;

	for(i=0; i<n; i++){
		for(j=n-1; j>i; j--){
			if(A[j].num < A[j-1].num){
				work = A[j];
				A[j] = A[j-1];
				A[j-1] = work;
			}
		}
	}
}

int partition(Card *A, int p, int r)
{
	Card work;
	int x = A[r].num;
	int i = p-1, j;

	for(j=p; j<r; j++){
		if(A[j].num <= x){
			i=i+1;
			work = A[i];
			A[i] = A[j];
			A[j] = work;
		}
	}

	work = A[i+1];
	A[i+1] = A[r];
	A[r] = work;

	return i+1;

}



void quicksort(Card *A, int p, int r)
{
	int q;
	if(p < r){
		q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q+1, r);
	}
}


int main()
{
	int n;
	int i;
	int flag = 0;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf(" %c%d", &A[i].mark, &A[i].num);
		bubble[i] = A[i];
	}
	
	quicksort(A, 0, n-1);
	BubbleSort(bubble, n);

	for(i=0; i<n; i++){
		if(A[i].mark != bubble[i].mark)
			flag = 1;
	}

	if(flag == 1) 
		printf("Notstable\n");
	else 
		printf("Stable\n");


	for(i=0; i<n; i++){
		printf("%c %d", A[i].mark, A[i].num);
		if(i != n-1) printf("\n");
	}

	return 0;
}