#include<stdio.h>

int partition(int*,char*,int,int);
void quicksort(int*,char*,int,int);

int count=0;

int main(){
  int i,n,x;

  scanf("%d",&n);

  int A[n];
  char B[n];

  for(i=0;i<n;i++){
    scanf(" %c %d",&B[i],&A[i]);
  }

  quicksort(A,B,0,n-1);
  if(count==0)printf("stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i],A[i]);
  }

  return 0;
}
  
int partition(int *A,char *B,int p,int r){
  int x=0,hako1=0;
  int i,j;
  char hako2;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){

    if(A[j]<=x){
      i=i+1;
      hako1=A[i];
      A[i]=A[j];
      A[j]=hako1;
      hako2=B[i];
      B[i]=B[j];
      B[j]=hako2;
    }
  }
  hako1=A[i+1];
  A[i+1]=A[r];
  A[r]=hako1;
  hako2=B[i+1];
  B[i+1]=B[r];
  B[r]=hako2;

  return i+1;
}

void quicksort(int *A,char *B,int p,int r){
  int q;
  if(p<r){
    q=partition(A,B,p,r);
    quicksort(A,B,p,q-1);
    quicksort(A,B,q+1,r);
  }
}

