#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
typedef struct{
  char sub;
  int figure;
}card;
int partition(card*,int*,int,int);
void quicksort(card*,int*,int,int);
void swap(card*,int*,int,int);
int main(){
  int n,i,temp,r,l,max=INT_MIN,min=INT_MAX,flag=0;
  int *stablejudge;
  card *list;
  scanf("%d",&n);
  list=(card*)malloc(n*sizeof(card));
for(i=0;i<n;i++){
  scanf("%*c%c%d",&((list+i)->sub),&((list+i)->figure));
  if(max<((list+i)->figure))max=((list+i)->figure);
  else if(min>((list+i)->figure))min=((list+i)->figure);
}
stablejudge=(int*)malloc(max*sizeof(int));
  r=n-1;
  l=0;
  for(i=min;i<max;i++)*(stablejudge+i)=0;
quicksort(list,stablejudge,l,r);
for(i=min;i<max;i++){
  if(*(stablejudge+i)%2!=0){
    flag=1;
    break;
  }
}
printf("%s\n",(flag!=0)?"Not stable":"Stable");
  for(i=0;i<n;i++)printf("%c %d\n",((list+i)->sub),((list+i)->figure));
  return 0;
}
int partition(card *l,int *sj,int left,int right){
int i;
  for(i=left;i<right;i++){
    if((l+right)->figure>=(l+i)->figure){
      swap(l,sj,i,left);
      left++;
    }
  }
  swap(l,sj,left,right);
  return left;
}
void quicksort(card *l,int *sj,int left,int right){
int q;
  if(left<right){
    q=partition(l,sj,left,right);
    quicksort(l,sj,left,q-1);
    quicksort(l,sj,q+1,right);
  }
}
void swap(card *x,int *sj,int a,int b){
  card c;
  *(sj+((x+a)->figure))+=1;
  *(sj+((x+b)->figure))+=1;
  c=*(x+a);
  *(x+a)=*(x+b);
  *(x+b)=c;
}

