#include<stdio.h>
#define N 100000

int patition(int [],int,int);
void quickSort(int[],int,int);
void bubble(int);
void isStable(int);

int A[N];
int A_1[N];
char B[N];
char B_1[N];

int main(){

	int i,left=1,right;

	scanf("%d",&right);
	for(i=0;i<right;i++){
		scanf("%s%d",&B[i],&A[i]);
		A_1[i]=A[i];
		B_1[i]=B[i];
	}

	quickSort(A,left,right);
	bubble(right);
	isStable(right);
 
	for(i=0;i<right;i++){
		printf("%c %d\n",B[i],A[i]);
	}
	
	return 0;

}

int partition(int A[],int left,int right){

	int i=left-1,j,x=A[right-1],s=0;
	char c;

	for(j=left;j<right;j++){
		if(A[j]<=x){
			s=A[i];
  			A[i]=A[j];
  			A[j]=s;

			c=B[i];
  			B[i]=B[j];
  			B[j]=c;
  		
			i++;
		}
	}

	s=A[i];
	A[i]=A[right-1];
	A[right-1]=s;
  	 
	c=B[i];
	B[i]=B[right-1];
	B[right-1]=c;
  
	return i+1;
 
}

void quickSort(int A[],int left,int right){
 
  int q=0;
 
  if(left < right){
	q = partition(A,left,right);
	quickSort(A,left,q-1);
	quickSort(A,q+1,right);      
  }
 
}

void bubble(int right){

  int i,j,a=0;
  char c;
  for(i=0;i<right;i++){
	for(j=right-1;j>i;j--){
  		if( A_1[j] < A_1[j-1]){
    		a=A_1[j-1];
    		A_1[j-1]=A_1[j];
    		A_1[j]=a;

    		c=B_1[j-1];
    		B_1[j-1]=B_1[j];
    		B_1[j]=c;

  		}	 
	}
  }

}

void isStable(int right){
  int i,m=0;

  for(i=0;i<right;i++){
	if(B[i]==B_1[i]){
  	m++;
	} else {
  	break;
	}
  }
  if(m==right){
	printf("Stable\n");
  } else {
	printf("Not stable\n");
  }
}