#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000000
int Partition(int *,char *,int,int);
void QuickSort(int *,char *,int,int);
int A[MAX],B[MAX],key;
char C[MAX],D[MAX];
int main(){
  int n,i,count = 1;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf(" %c %d",&C[i],&A[i]);
    B[i] = A[i];
    D[i] = C[i];
  }

  QuickSort(A,C,0,n);
  for(i = 0;i<n;i++){
  if(A[i] == A[i+1]){
    if(C[i] == D[i] && C[i+1] == D[i+1]){
  count++;

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

  return 0;
}

int Partition(int *A,char *C,int p,int r){
  int i,j,x,tmp;
  char c;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;

      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;

      c = C[i];
      C[i] = C[j];
      C[j] = c;
    }
  }
  tmp = A[r];
  A[r] = A[i+1];
  A[i+1] = tmp;

 c = C[r];
  C[r] = C[i+1];
  C[i+1] = c;


  return i+1;

}
void QuickSort(int *A,char *C,int p,int r){
  int q;
  if(p < r){
    q = Partition(A,C,p,r);
  key = q;
  QuickSort(A,C,p,q-1);
  QuickSort(A,C,q+1,r);
  }
  }