#include<stdio.h>
#include<stdlib.h>
typedef struct{
  int value;
  char sign;
} Card;
int partition(Card*,int,int);
void quickSort(Card*,int,int);
int isStable(Card*,Card*,int);

int main() 
{
  int i,n;
  Card *a,*b;
  
  scanf("%d",&n);
  a=(Card*)malloc(sizeof(Card)*n);
  b=(Card*)malloc(sizeof(Card)*n);
  for(i=0; i<n; i++) {
    scanf(" %c%d",&a[i].sign,&a[i].value);
    b[i] = a[i];
  }
  quickSort(a,0,n-1);
  if(!isStable(b,a,n)) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++) 
    printf("%c %d\n",a[i].sign,a[i].value);
  
  free(a);
  free(b);
  
  return 0;
}

void quickSort(Card a[],int p,int r) 
{
  int q;
  if(p<r) {
    q = partition(a,p,r);
    quickSort(a,p,p-1);
    quickSort(a,p+1,r);
  }
}

int partition(Card a[],int p,int r)
{
  int x,i,j;
  Card tmp;
  x = a[r].value;
  i = p-1;
  for(j=p; j<r; j++) {
    if(a[j].value<=x) {
      i = i+1;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
    }
  }
  tmp = a[i+1];
  a[i+1] = a[r];
  a[r] = tmp;
  return i+1;
}

int 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; b<n; b++)
	  return in[i].value == in[j].value && in[i].sign == out[b].sign && in[j].sign == out[a].sign && in[i].value == out[b].value && in[j].value == out[a].value;
}