#include<stdio.h>

struct fun{
	char c;
	int b;
}f[100010],f1[100010],t,h;

int Partition(fun a[],int p,int r){
   a[0]=a[p];
   int k=a[0].b;
   while(p<r){
   	while(p<r&&a[r].b>=k)  r--;
   	  a[p]=a[r];
   	while(p<r&&a[p].b<=k)  p++;
   	  a[r]=a[p];
   }
   a[p]=a[0];
   return p;
}
void Quicksort(fun a[],int p,int r){
	if(p<r){
     int q = Partition(a, p, r);
      Quicksort(a, p, q-1);
      Quicksort(a, q+1, r);
   }
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf(" %c %d",&f[i].c,&f[i].b);
		f1[i].c=f[i].c;
		f1[i].b=f[i].b;
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<=n-i;j++){
			if(f1[j].b>f1[j+1].b){
				h=f1[j];
				f1[j]=f1[j+1];
				f1[j+1]=h;
			}
		} 
	}
	Quicksort(f,1,n);
	int leap;
	 for(int i=1;i<=n;i++){
		if(f[i].c!=f1[i].c){
			leap=1;
			break;
		}
		  else
		  leap=0;
		}
	if(leap==1)
	  printf("Not stable\n");
	if(leap==0)
	  printf("Stable\n");
    for(int i=1;i<=n;i++){
		printf("%c %d\n",f[i].c,f[i].b);
	}
	return 0;
}