# include <stdio.h>

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

int part ( card [],int ,int);
void quickSort( card [],int ,int);
int main(){
  int n,i ,t;char tc;
  scanf("%d\n" , &n);
  card arr[n] ,input[n];
  for ( i = 0; i < n; i++){
    if ( i == n-1 ) { scanf("%c %d",&arr[i].mark,&arr[i].value);
  
    }else{
      scanf("%c %d ",&arr[i].mark,&arr[i].value);
    }
    input[i].mark = arr[i].mark;
    input[i].value = arr[i].value;
    //  printf("output %c %d",arr[i].mark,arr[i].value);
    
  }

  for( i=0;i<n;i++){
    //printf("1111%c %d",arr[i].mark,arr[i].value);
  }   
  int flag = 1 ;
  while ( flag){
    flag = 0;
    for ( i = n - 1 ;  i >= 1; i--){
      if ( arr[i].value < arr[ i-1 ].value){
	t = arr[i].value; arr[i].value = arr[ i-1 ].value; arr[i-1].value = t;
	tc = arr[i].mark; arr[i].mark = arr[ i-1 ].mark; arr[i-1].mark = tc;

	flag = 1;
      }
    }
  }

  quickSort(input, 0,n-1);


   flag = 1;
  for ( i = 0; i < n; i++){
    if( input[i].mark != arr[i].mark){
      flag =0;break;
    }
  }
  if (flag == 1){printf("Stable\n");}
  else if ( flag == 0)  { printf("Not stable\n");}
  
    for ( i = 0; i < n; i++){
      printf("%c %d\n",input[i].mark,input[i].value);
    }
  
  return 0;
}


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

int  part (card a[] ,int p ,int r){
  int x = a[r].value ,t ,k;char tc;
  int j, i = p-1;
  for ( j = p ; j < r ; j++ ){
    if ( a[j].value  <= x){
      i++;
      t = a[i].value; a[i].value = a[j].value; a[j].value =t;
      tc = a[i].mark; a[i].mark = a[j].mark; a[j].mark =tc;
    }
  }
  t = a[i+1].value; a[i+1].value = a[r].value ; a[r].value=t;
  tc = a[i+1].mark; a[i+1].mark = a[r].mark ; a[r].mark=tc;
  return i+1;
}

