#include<stdio.h>
#define LEN 100010
#define STABLE 1
#define NOTSTABLE 0

typedef struct{
  char c;
  int n;
}Card;

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

int main()
{
  int n;
  Card A[LEN], B[LEN], card;
  int p, r;
  int flag=STABLE;

  int i, j, k;
  char c;

  //read
  scanf("%d", &n);
  scanf("%c", &c);
  for(i=0; i<n; i++)
    {
      scanf("%c %d", &A[i].c, &A[i].n);
      scanf("%c", &c);
      B[i]=A[i];
      //printf("%c %d\n", A[i].c, A[i].n);
    }


  //bublle sort
  for(i=0; i<n; i++)
    {
      for(j=n-1; j>i-1; j--)
	{
	  if(B[i].n>B[j].n)
	    {
	      card=B[i];
	      B[i]=B[j];
	      B[j]=card;
	    }
	}
    }

  //quick sort
  p=0;
  r=n-1;
  quicksort(&A[0], p, r);

  //is this stable?
  for(i=0; i<n-1; i++)
    {
      if(A[i].c!=B[i].c)
	{
	  flag=NOTSTABLE;
	  break;
	}
    }

  //print
  if(flag==STABLE)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++)printf("%c %d\n", A[i].c, A[i].n);
  /*
  printf("\n");
  for(i=0; i<n; i++)printf("%c %d\n", B[i].c, B[i].n);
  */


  return 0;
}


//quicksort
void quicksort(Card *A, int p, int r)
{
  int q;
  if(p<r)
    {
      q = partion(A, p, r);
      quicksort(A, p, q-1);
      quicksort(A, q+1, r);
    }
}

//partion
int partion(Card *A, int p, int r)
{
  int x = A[r].n;
  int i = p-1;
  int j, n;
  Card k;

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

  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  return i+1;
}