#include<stdio.h>
struct A{
  char m;
  int value;
  int bango;
};
int partiton(struct A *,int,int);
void quicksort(struct A *,int,int);
int main(){
  int i,n,x,y,j,flag=0;
  scanf("%d",&n);
  struct A a[n];
  for(i=0;i<n;i++){
    scanf(" %c %d",&a[i].m,&a[i].value);
    a[i].bango=i;
  }
  quicksort(a,0,n);
  i=partition(a,0,n);
  for(j=0;j<n-1;j++){
    if(a[j].bango>a[j+1].bango)flag++;
  }
  if(flag!=0)printf("Not stable\n");
  else printf("Stable\n");
  for(j=0;j<n;j++){
    printf("%c %d\n",a[j].m,a[j].value);
  }
  return 0;
}

void quicksort(struct A a[],int p,int r){
  int q;
  if(p<r){
    q=partition(a,p,r);
    quicksort(a,p,q-1);
    quicksort(a,q+1,r);
  }
}
int partition(struct A a[],int p,int r){
  struct A x,y;
  int i,j;
  x = a[r-1];
  i = p-1;
  for(j=p;j<r-1;j++){
    if(a[j].value<=x.value){
      i=i+1;
      y=a[i];
      a[i]=a[j];
      a[j]=y;
    }
  }
  y=a[i+1];
  a[i+1]=a[r-1];
  a[r-1]=y;
  return i+1;
}