#include<stdio.h>

#define N 100000

typedef struct{
  int Num;
  char Spel;
}Tarot;

Tarot Qui[N];

void QuickS(int, int);
int Par(int,int);

int main(){
  Tarot Bub[N],temp;
  int i;
  int flag=0,judge=0;
  int loop;
    
  scanf("%d ",&loop);
  for(i=0;i<loop;i++){
    scanf("%s %d",&Qui[i].Spel,&Qui[i].Num);
    Bub[i].Spel=Qui[i].Spel;
    Bub[i].Num=Qui[i].Num;
  }

  QuickS(0,loop-1);
  
  while(1){
    if(judge==0)break;
    judge=0;
    for(i=loop-1;i>0;i--){
      if(Bub[i].Num<Bub[i-1].Num){
	temp=Bub[i];
	Bub[i]=Bub[i-1];
	Bub[i-1]=temp;
	judge=1;
      }
    }
  }
  

  for(i=0;i<loop;i++){
    if(Qui[i].Spel!=Bub[i].Spel){
      flag=1;
      break;
    }
  }

  if(flag==0){
    printf("Stable\n");
  }

  else if(flag==1){
    printf("Not stable\n");
  }
  
  for(i=0;i<loop;i++){
    printf("%c ",Qui[i].Spel);
    printf("%d\n",Qui[i].Num);
  }

  return 0;
}

void QuickS(int zero,int set){
  int point;

  if(zero<set){
    point=Par(zero,set);
    
    QuickS(zero,point-1);
    QuickS(point+1,set);
    
  }
  
}

int Par(int zero,int set){
  int init;
  int j;
  Tarot last,temp;
  
  last=Qui[set];
  init=zero-1;
  
  for(j=zero;j<set;j++){
    
    if(last.Num>=Qui[j].Num){
      init+=1;
      temp=Qui[init];
      Qui[init]=Qui[j];
      Qui[j]=temp;
    }
  }
  
  temp=Qui[init+1];
  Qui[init+1]=Qui[set];
  Qui[set]=temp;
  
  return init+1;
}

