#include<stdio.h>
#include<stdlib.h>



typedef struct{
  int key;
  char s;
}card;






int n;



int partition(card **A,int p,int r){
  int x;
  card *swap;
  x=A[r]->key;
  int i,j;
  i=p;
  for(j=p;j<=r;j++){
    if((A[j]->key) <= x){
       swap=A[i];
       A[i]=A[j];
       A[j]=swap;
       i++;
    }
  }
  return i-1;
}

void q_sort(card **A,int a,int b){
  int q;
  q=partition(A,a,b);
  if(q-1 > a) q_sort(A,a,q-1);
  if(q+1 < b) q_sort(A,q+1,b);
}


void b_sort(card **B){
  int i,j,count;
  card *swap;
  for(i=0;i<n-1;i++){
    count=0;
    for(j=n-1;j>i;j--){
      if(B[j]->key <B[j-1]->key){
        swap=B[j];
        B[j]=B[j-1];
        B[j-1]=swap;
        count=1;
     }
   }
   if(count==0) break;
  }
}


int main(){
  int i;
  card **A,**B;
  scanf("%d",&n);
  A=malloc(n*sizeof(card *));
  B=malloc(n*sizeof(card *));
  for(i=0;i<n;i++){
    A[i]=malloc(sizeof(card));
    B[i]=malloc(sizeof(card));
    scanf(" %c",&(A[i]->s));
    scanf("%d",&(A[i]->key));
    B[i]->key=A[i]->key;
    B[i]->s=A[i]->s;
  }
  q_sort(A,0,n-1);
  b_sort(B);
  for(i=0;i<n;i++){
    if(A[i]->s != B[i]->s) break;
  }
  if(i!=n) printf("Not stable\n");
  else printf("Stable\n");
  for(i=0;i<n;i++) printf("%c %d\n",A[i]->s,A[i]->key);
  return 0;
}
  