#include <stdio.h>
#include <stdlib.h>

int q;

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

int part(card *a, int p, int r){
  int i, j, x;
  card tmp;

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

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

  return i+1;
}

void quick(card *a, int p, int r){
  if(p < r){
    q = part(a, p, r);
    quick(a, p, q-1);
    quick(a, q+1, r);
  }
}

isStable(card *in, card *out, int n){
  int i, j, a, b;
  for(i = 0 ; i < n; i++)
    for(j = i+1; j < n; j++)
      for(a = 0; a < n; a++)
        for(b = a+1; a < n; b++)
          if(in[i].num == in[j].num && (in[i].suit == out[b].suit && in[i].num == out[b].num) && (in[j].suit == out[a].suit && in[j].num == out[a].num))
            return 0;
  return 1;
}

int main(){
  int i, j, q, n, isstb;

  scanf("%d", &n);
  card *a;
  a = malloc(sizeof(card) * n);
  card *in;
  in = malloc(sizeof(card) * n);

  in = a;

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

  quick(a, 0, n-1);
  isstb = isStable(in, a, n);

  if(isstb == 1)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for(i = 0; i < n; i++)
    printf("%c %d\n", a[i].suit, a[i].num);


  return 0;
}