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

#define N 100001

typedef struct{
  char card;
  int num;
}Record;

 
int partition(Record *, int, int);
void quicksort(Record *, int, int);
void Bubblesort(Record *);
int Stable(Record *, Record *);

int n;

int main () {
  int i;
  char str;
  Record data[N], smp[N];

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) {
    scanf(" %c %d",&data[i].card,&data[i].num);
    smp[i] = data[i];
  }

  
  quicksort(data, 1, n);
  Bubblesort(smp);

  if(Stable(data, smp) == 1) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 1 ; i <= n ; i++) {
    printf("%c %d\n", data[i].card, data[i].num);
  }

  

  return 0;
}







int partition(Record *A, int p, int r) {
  int i, j, x = 0, tmp = 0;
  char str;
  Record data;

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


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

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

  return i+1;
}


void quicksort(Record *p1, int p, int r) {
  int q = 0;

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

void Bubblesort(Record *data) {
  int i, j;
  Record tmp;

  for(i = 1 ; i <= n ; i++) {
    for(j = n ; j >= i + 1 ; j--) {
      if(data[j].num < data[j-1].num) {
	tmp = data[j];
	data[j] = data[j - 1];
	data[j - 1] = tmp;
      }
    }
  }
}










int Stable(Record *A, Record *smp) {
  int i, j, a, b;

  for(i = 1 ; i <= n ; i++) {
    if(A[i].card != smp[i].card) return 0;
  }

  return 1;
}

