#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=0,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,j,x=0,s=0;
  char c;
  x=A[right-1];
  i=left;

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

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

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

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");
  }
}