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

#define false 0
#define true 1


void swapInt( int *n1, int *n2) {

int tmp;

tmp = *n1;
*n1 = *n2;
*n2 = tmp;

}

void swapChar( char *c1, char *c2) {

char tmp;

tmp = *c1;
*c1 = *c2;
*c2 = tmp;

}


int partition( int *a, char *c, int p, int r, int* isStable) {

int x;
int i, j;

x = a[r];
i = p-1;

for( j=p; j<r; j++) {
  if( a[j] <= x ) {
    i++;
    swapInt( &a[i], &a[j]);
    swapChar( &c[i], &c[j]);
    *isStable = false;
  }
}
swapInt( &a[i+1], &a[r]);
swapChar( &c[i+1], &c[r]);
return i+1;

}


quickSort(int*  a, char* c, int p, int r, int* isStable) {
  
  int q;

  if( p < r) {
    q = partition( a, c, p, r, isStable);
    quickSort( a, c, p, q-1, isStable);
    quickSort( a, c, q+1, r, isStable);
  }
} 


main() {

int n;
int* a;
char* c;
int* isStable;

int i;

*isStable = true;

scanf("%d", &n);

a = malloc( sizeof( int ) * n );
c = malloc( sizeof( char ) * n );

for( i=0; i<n; i++) {
scanf(" %c %d", &c[i], &a[i]);
}

quickSort( a, c, 0, n-1, isStable);

if( *isStable == true) {
printf("Stable\n");
}else {
printf("Not stable\n");
}

for( i=0; i<n; i++) {
printf("%c %d\n", c[i], a[i]);
}
return 0;
}