typedef struct{
  int n;
  char m;
}Card;
void qsort(Card*,int,int);
int  part(Card*,int,int);

main(){
  int i,g,p,r,count=0;
  char B[100000];
  Card A[100000];
  scanf("%d",&g);
  for(i=0;i<g;i++){
    scanf(" %c%d",&A[i].m,&A[i].n);
    B[i] = A[i].m;
  }

  p=0;
  r=g-1;
  qsort(&A[0],p,r);
  for(i=0;i<g;i++){
    if(B[i] != A[i].m)count++;
  }
  if(count>0)printf("Not stable\n");
  else if(count == 0)printf("Stable\n");
  for(i=0;i<g;i++)printf("%c %d\n",A[i].m,A[i].n);
  return 0;
}


void qsort(Card *A ,int p,int r){
  int q;
  if(p<r){
    q = part(A,p,r);
    qsort(A,p,q-1);
    qsort(A,q+1,r);
  }
}

int part(Card *A,int p,int r){
  int i,j,x,taihi;
  char taihi2;
  x = A[r].n;
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].n<=x){
      i++;
      taihi = A[i].n;
      A[i].n = A[j].n;
      A[j].n = taihi;
      taihi2 = A[i].m;
      A[i].m = A[j].m;
      A[j].m = taihi2;

   }
}
  taihi = A[i+1].n;
  A[i+1].n = A[r].n;
  A[r].n = taihi;
  taihi2 = A[i+1].m;
  A[i+1].m = A[r].m;
  A[r].m = taihi2;

  return i+1;
}