#include<stdio.h>
#include<stdlib.h>
#define VMAX 999999999
typedef struct{
  int n;
  char c;
}member;
void quickSort(member *,int,int);
int partition(member *,int,int);
void swap(member *,member *);
void countingSort(member *,member *,int);
int main(){
  int i,n,flag=0;
  member *A,*B,*C;
  scanf("%d",&n);
  A = (member *)malloc(n * sizeof(member));
  B = (member *)malloc((n+1) * sizeof(member));
  C = (member *)malloc((n+1) * sizeof(member));
  
  for(i=0;i<n;i++){
    scanf(" %c",&A[i].c);
    scanf("%d",&A[i].n);
  }
  for(i=0;i<n;i++){
    B[i].c=A[i].c;
    B[i].n=A[i].n;
  }
  
  quickSort(A,0,n-1);
  countingSort(B,C,n);
  

  for(i=0;i<n;i++){
    if(!(A[i].c==C[i].c && A[i].n==C[i].n)){
      flag = 1;
      break;
    }
  }


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

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

  return 0;
}

void quickSort(member *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(member *A,int p,int r){
  int i,j;
  member x;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].n <= x.n){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

void swap(member *x,member *y){
  member r;
  r=*x;
  *x=*y;
  *y=r;
}


void countingSort(member *A,member*B,int n){
  int i,C[VMAX+1];
  
    for(i=0;i<=VMAX;i++){
    C[i]=0;
  }

  for(i=0;i<n;i++){
    C[A[i].n]++;
  }

  for(i=1;i<VMAX;i++){
    C[i]=C[i]+C[i-1];
  }
  
  for(i=n-1;i>=0;i--){
    B[C[A[i].n]-1].n=A[i].n;
    B[C[A[i].n]-1].c=A[i].c;
    C[A[i].n]--;
  }
}

