#include<stdio.h>
#include<stdlib.h>
typedef struct{
  char c;
  int n;
} data;
int flag=0;
int partition(data*, int, int);
int main(){
  int n, i, temp;
  data *A;
  scanf("%d ",&n);
  A = (data *)malloc(sizeof(data) * n);
  for(i=0; i<n; i++){
    scanf("%c%d",&A[i].c,&A[i].n);
    if(i != n - 1) scanf(" ");
  }
  for(i=0; i<n; i++)
    temp = partition(A, 0, n-1);
  flag ? printf("Not stable\n") : printf("Stable\n");
  for(i=0; i<n; i++){
    printf("%c %d\n",A[i].c,A[i].n);
  }
  free(A);
  return 0;
}

int partition(data *A, int p, int r){
  int x, i, j;
  data temp;
  x = A[r].n;
  i = p - 1;
  for(j=p; j<=r-1; j++){
    if(A[j].n < x){
      i = i + 1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
      flag = 1;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}