#include<stdio.h>

#define N 100000

typedef struct{
  char gara;
  int value;
} card;

void Quicksort(int, int);
int Partition(int, int);

card A[N], B[N];

int main(){
  int n, i, s = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf(" %c%d", &A[i].gara, &A[i].value);
    B[i] = A[i];
  }
  
  Quicksort(1, n);

    for(i = 0; i < n; i++){
      for(j = i; j < n; j++){
	for(k = 0; k < n; k++){
	  for(l = k; k < n; l++){
	    if(A[i].value == A[j].value && A[i].value == B[l].value && A[i].gara == B[l].gara && A[j].value == B[k].value) s++;
    }
     
  if(s != 0) printf("Stable\n");
  else printf("Not stable\n");
  
  for(i = 1; i <= n; i++) printf("%c %d\n", A[i].gara, 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 y;

  x = A[r].value;
  i = p - 1;

  for(j = p; j < r-1; j++){
    if(A[j].value <= x){
      i++;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }

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

  return i+1;

}