#include <stdio.h>

#define MAX 100000

typedef struct{
  char mark;
  int value;
} Card;

void quicksort(int, int);
int partition(int, int);
int Judge(int);

Card A[MAX], a[MAX];
int n;

int main()
{
  int i;

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    scanf(" %c%d", &A[i].mark, &A[i].value);
    a[i] = A[i];
  }
  
  quicksort(0, n-1);

  if( Judge(n) == 0 ) printf("Stable\n");
  else printf("Not stable\n");
  
  for( i = 0 ; i < n ; i++ )
    printf("%c %d\n", A[i].mark, A[i].value);

  return 0;
}

void quicksort(int p, int r)
{
  int q;

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

int partition(int p, int r)
{
  int i, j, x;
  Card tmp;
  
  x = A[r].value;
  i = p-1;
  
  for( j = p ; j < r ; j++ ){
    if( A[j].value <= x){
      i++;
      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;
}

int Judge(int n)
{
  int i;

  for( i = 0 ; i < n ; i++ )
    if( A[i].mark != a[i].mark ) return 1;
  
  return 0;

}