#include<stdio.h>



#define N 100001



void BubbleSort(int a[],char c[],int n){
  int st;
  char stc;
  int i,j;
  for(i=0;i<n;i++){
    for(j=n;j>i-1;j--){
      if(a[j]<a[j-1]){
	st=a[j];
	a[j]=a[j-1];
	a[j-1]=st;
	stc=c[j];
	c[j]=c[j-1];
	c[j-1]=stc;
      }
    }
  }
}


int Partition(int a[],char c[],int p,int r){
  int x,i,j,st;
  char stc;

  x=a[r];
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(a[j]<=x){
      i++;

      //exchange a[i] and a[j]
      st=a[i];
      a[i]=a[j];
      a[j]=st;

      stc=c[i];
      c[i]=c[j];
      c[j]=stc;

    }
  }

  //exchange a[i] and a[j]
    st=a[i+1];
    a[i+1]=a[r];
    a[r]=st;

    stc=c[i+1];
    c[i+1]=c[r];
    c[r]=stc;

    return i+1;

}


void QuickSort(int a[],char c[],int p,int r){
  int q;
  if(p<r){
    q=Partition(a,c,p,r);
    QuickSort(a,c,p,q-1);
    QuickSort(a,c,q+1,r);
  }
}

int main(){
 
  int n,i,a1[N],a2[N];
  char c1[N],c2[N];
  int flag=1;
  scanf("%d",&n)  ;

  for(i=0;i<n;i++){
    scanf(" %c %d",&c1[i],&a1[i]);
    a2[i]=a1[i];
    c2[i]=c1[i];
  }


  QuickSort(a1,c1,0,n-1);
  BubbleSort(a2,c2,n-1);

  for(i=0;i<n;i++){
    if(c1[i]!=c2[i]){
      printf("Not stable\n");
      flag=0;
      break;
    }
  }

  if(flag==1)printf("Stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",c1[i],a1[i]);
  }

  return 0;
}