#include<stdio.h>
#include<limits.h>

#define MAX 100000

typedef struct{
  char c;
  int m;
}card;

int partition(int,int);
void quicksort(int,int);
void merge(int,int,int,card *);
void mergeSort(int,int,card *);

card A[MAX];

int main(){

  int i,n,p=0;
  char c;
  card copy[MAX];


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

  mergeSort(0,n,copy);
  quicksort(p,n-1);
  for(i=0;i<n;i++){
    if(copy[i].c!=A[i].c){
      printf("Not stable\n");
      break;
    }
    if(i==n-1)printf("Stable\n");
  }
 
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].m);
  }


  return 0;

}

int partition(int p,int r){
  card tmp;
  int x,i,j;
  x = A[r].m;
  i = p-1;
  for( j = p; j< r;j++){
    if (A[j].m <= x){
      i = i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}
void quicksort(int p,int r){
  int q;

  if(p<r){
    q=partition(p,r);
    quicksort(p,q-1);
    quicksort(q+1,r);

  }

}
void merge(int left,int mid,int right,card B[]){
  int i,j,k;
  int n1 = mid-left;
  int n2 = right-mid;
  card L[MAX],R[MAX];
 
  for(i = 0;i<n1;i++){
    L[i]=B[left+i];
  }
 
  for(i = 0;i<n2;i++){
    R[i]=B[mid+i];
  }
   
  L[n1].m=INT_MAX;
  R[n2].m=INT_MAX;
  i=0;
  j=0;
  for(k = left; k<right; k++){
    if(L[i].m<=R[j].m){
      B[k]=L[i++];
    }
    else {
      B[k]=R[j++];
    }
  
  }
   
}
void mergeSort(int left,int right,card B[]){
  if(left+1 < right ){
    int mid = (left+right)/2;
    mergeSort(left,mid,B);
    mergeSort(mid,right,B);
    merge(left,mid,right,B);
  }
}