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

void quicksort(int, int);
int Partition(int, int);
void BubbleSort();

typedef struct{
  int num;
  char mark[2];
}card;

card A[100000];
card B[100000];
int n;

int main(){
  int i, flag=0;

  scanf("%d",&n);
  if( n<1 || 100000<n ) exit(0);
  
  for( i=0 ; i<n ; i++ ){
    scanf("%s",A[i].mark);
    scanf("%d",&A[i].num);

    B[i] = A[i];
  }
  
  quicksort(0, n);

  BubbleSort();

  for( i=0 ; i<n ; i++ ){
    if( strcmp(A[i].mark, B[i].mark) != 0) flag=1;
  }

  if(flag == 1) printf("Not Stable\n");
  else printf("Stable\n");
  
  for( i=0 ; i<n ; i++ ){
    printf("%s %d\n",A[i].mark, A[i].num);
  }

  return 0;
}

void quicksort(int l, int r){
  int q;
  
  if(l < r){
    q = Partition(l, r);
    quicksort(l, q-1);
    quicksort(q+1, r);
  }
}

int Partition(int l, int r){
  int i, j, x, k;
  card tmp;

  x = A[r-1].num;
  i = l-1;

  for( j=l ; j<r-1 ; j++ ){
    if( A[j].num <= x ){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  
  tmp = A[i+1];
  A[i+1] = A[r-1];
  A[r-1] = tmp;
  
  return i+1;
}

void BubbleSort(){
  int i, j;
  card tmp;
  
  for( i=0 ; i<n ; i++ ){
    for( j=n-1 ; i<j ; j-- ){
      if(B[j].num < B[j-1].num){
	tmp = B[j];
	B[j] = B[j-1];
	B[j-1] = tmp;
      }
    }
  }
}