#include <stdio.h>
#define N 100000

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

int partition(Card *, int, int);
void quicksort(Card *, int, int);

int main(){
  Card a[N], list[N];
  int n, count = 0, flag1 = 0, flag2 = 0, i, j;

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

  for(i = 0; i < n - 1; i++){
    for(j = i + 1; j < n; j++){
      if(a[i].num == a[j].num && a[i].num != flag2){
	list[count] = a[i];
	count++;
	flag2 = a[i].num;
	break;
      }
    }
  }

  quicksort(a, 0, n - 1);
  for(j = 0; j < count; j++){
  for(i = 0; i < n - 1; i++){
    if(list[flag1].num == a[i].num){
      if(a[i].mark == list[flag1].mark){
	flag1++;
	break;
      }
    }
  }
}

  printf("");
  if(flag1 == count) printf("Stable\n");
  else printf("Not stable\n");

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

  return 0;
}

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 partition(Card *a, int p, int r){
  Card change;
  int x, i, j;

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

  for(j = p; j < r; j++){
    if(a[j].num <= x){
      i++;
      change = a[i];
      a[i] = a[j];
      a[j] = change;
    }
  }
  change = a[i + 1];
  a[i + 1] = a[r];
  a[r] = change;

  return i + 1;
}