#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int Partition(char [], int [], int, int);
void Quicksort(char [], int [], int, int);
void BubbleSort(char [], int [], int);

int q;

int main(void){

  int A[MAX+1];
  char C[MAX+1];
  char BC[MAX+1];
  int BN[MAX+1];

  int i, p, n;
  int count = 0;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    scanf(" %c %d",&C[i], &A[i]);


  for(i = 1; i<=n;i++){
    BC[i] = C[i];
    BN[i] = A[i];
  }


  BubbleSort(BC, BN, n); 

  p = 1;

  Quicksort(C, A, p, n);

  for(i = 1; i <= n;i++){
    if(BN[i] == A[i] && BC[i] == C[i])
      count++;
  }

  if(count == n)
    printf("Stable\n");

  else
    printf("Not stable\n");


  for(i=1;i<=n;i++)
    printf("%c %d\n",C[i], A[i]);

  return 0;
}

void BubbleSort(char BC[], int BN[], int len){

  int i,j;
  char tmpC;
  int  tmpN;
  
  for(i=1;i<=len;i++){
    for(j=len;j>=i+1;j--){
      if(BN[j] < BN[j-1]){
	tmpN = BN[j-1];
	tmpC = BC[j-1];
	BN[j-1] = BN[j];
	BC[j-1] = BC[j];
	BN[j] = tmpN;
	BC[j] = tmpC;
      }
    }
  }

}



int Partition(char C[], int A[], int p, int r){

  int i, j;
  char tmpC,x;
  int  tmpN, y;

  x = C[r];
  y = A[r];
  i = p - 1;

  for(j = p;j<r;j++){
    if(A[j] <= y){
      i = i + 1;
      tmpN = A[j];
      tmpC = C[j];
      A[j] = A[i];
      C[j] = C[i];
      A[i] = tmpN;
      C[i] = tmpC;
    }
  }
  
  tmpN = A[i+1];
  tmpC = C[i + 1];
  A[i+1] = A[r];
  C[i+1] = C[r];
  A[r] = tmpN;
  C[r] = tmpC;

  return i+1;
}


void Quicksort(char C[], int A[], int p, int r){


  if(p < r){
    q = Partition(C, A, p, r);
    Quicksort(C, A, p, q-1);
    Quicksort(C, A, q+1, r);
    }
}