#include <stdio.h>
#define true 1
#define false 0
typedef struct{
  char kind;
  int num;
} card;
int isStable(card *, card *);
void bubbleSort(card *);
int partition(card *, int, int);
void quicksort(card *, int, int);
int n;

int main()
{
  int i;
  card A[100000], in_copy[100000];
  
  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) scanf(" %c %d",&A[i].kind,&A[i].num);

  for(i = 0 ; i < n ; i++) in_copy[i] = A[i];
  
  quicksort(A, 0, n-1);
  bubbleSort(in_copy);

  if(isStable(A, in_copy) == true) printf("Stable\n");
  else if(isStable(A, in_copy) == false) printf("Not stable\n");

  for(i = 0 ; i < n ; i++) printf("%c %d\n",A[i].kind,A[i].num);

  return 0;
}

int partition(card *A, int p, int r)
{
  int x, i, j;
  card for_change;
  
  x = A[r].num;
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(A[j].num <= x){
      i++;
      for_change = A[i];
      A[i] = A[j];
      A[j] = for_change; }
  }

  for_change = A[i+1];
  A[i+1] = A[r];
  A[r] = for_change;

  return ++i;
}

void quicksort(card *A, int p, int r)
{
  int q;
  
  if( p < r){
    q = partition(A, p , r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r); }

}

int isStable(card *in, card *out)
{
  int i, count = 0;

  for(i = 0 ; i < n ; i++){
    if(in[i].num == out[i].num && in[i].kind == out[i].kind) count++; }

  if(count == n) return true;

  return false;  
} 

void bubbleSort(card *A)
{
  int for_exit = true, i;
  card for_change;
  
  while(for_exit == true){
    for_exit = false;
    for(i = n-1 ; i > 0 ; i--){
      if(A[i].num < A[i-1].num){
	for_change = A[i];
	A[i] = A[i-1];
	A[i-1] = for_change; 
	for_exit = true; }
    }
  }
  
}

