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

typedef struct{
  char mark;
  int number;
} card;

int partition(card *,int,int);
void quicksort(card *,int,int);
int isStable(card *,card *);

card *A;
int n;

int main(){
  int i;
  card *in;

  scanf("%d",&n);

  A = (card *)malloc(sizeof(card) * n);
  if(A == NULL) exit(0);

  in = (card *)malloc(sizeof(card) * n);
  if(in == NULL) exit(0);

  for(i = 0;i < n;i++){
    in[i] = A[i];
  }

  for(i = 0;i < n;i++){
    scanf("%s %d",&A[i].mark,&A[i].number);
  }

  quicksort(A,0,n-1);

  /* 出力 */
  if(isStable(in,A) == 1) printf("Stable\n");
  if(isStable(in,A) == 0)printf("Not stable\n");
  for(i = 0;i < n;i++){
    if(i > 0) printf("\n");
    printf("%c %d",A[i].mark,A[i].number);
  }
  printf("\n");
    return 0;
}

int partition(card *A,int p,int r) /* p = 要素の始め、r = 要素の終わり */
{
  int x,i,j;
  card stack;

  x = A[r].number; /* xはpartitionの基準 */
  i = p - 1;

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

  return i+1; /* 次のpartitionの基準となる値を返す */
}

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 isStable(card *in,card *out)
{
  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;b < n;b++){
	  if((in[i].number == in[j].number) && (in[i].number == out[b].number) && (in[j].number == out[a].number))
	    return 0;
	}
      }
    }
  }
  return 1;
}