#include <stdio.h>
#define MAX 100000

int partition( int *A, int *Order, int p, int r );

int Quicksort( int *A, int *Order, int p, int r );

int isStable( int *in, int *out, int N );

int main(void)
{
    int Arr[MAX] = {};
    int Original[MAX] = {};
    int Order[MAX] = {};
    char str[MAX][2] = {};
    int i = 0;
    int flag = 0;
    int order = 0;
     
    scanf("%d\n", &order);
     
    for ( i = 0; i < order; i++ ) {
        scanf("%s", str[i]);
        scanf("%d", &Arr[i]);
        Original[i] = Arr[i];
        Order[i] = i;
    }
    
    
    
    Quicksort(Arr, Order, 0, order-1);
    flag = isStable( Original, Arr, order );
    if ( flag < 0 ) {
        printf("Not stable\n");
    } else {
        printf("Stable\n");
    }
    
    for ( i = 0; i < order - 1 ; i++ ) {
        printf("%c %d\n", str[i][0], Arr[Order[i]]);
    }
    printf("%c %d\n", str[i][0], Arr[Order[i]]);
    return 0;
}
 
int partition( int *A, int *Order, int p, int r ) 
{
    int x = 0;
    int i = 0;
    int j = 0;
    int tmp = 0;
	static int kaisu = 0;
     
    x = A[Order[r]];
    i = p - 1;
    for ( j = p; j < r; j++ ) {
        if ( A[Order[j]] <= x ) {
            i = i+1;
            tmp = Order[i];
            Order[i] = Order[j];
            Order[j] = tmp;
        }
    }
     
    tmp = Order[r];
    Order[r] = Order[i+1];
    Order[i+1] = tmp;
   // printf("回数：%d p:%d r:%d\n", kaisu, p, r);
   /* for ( j = p; j < r + 1; j++ ) {
        printf("%d ", Order[j]);
    }
    kaisu++;
    printf("\n");*/
    return i+1;
}

int Quicksort( int *A, int *Order, int p, int r )
{
	int q = 0;
	static int kaisu = 0;
	if ( p < r ) {
		q = partition( A, Order, p, r );
		//printf("回数：%d partition：%d p:%d r:%d\n\n", kaisu, q, p, r);
		kaisu++;
		Quicksort(A, Order, p, q-1);
		Quicksort(A, Order, q+1, r);
	}
	return 0;
}



int isStable( int *in, int *out, int N )
{
    int i = 0;
    int j = 0;
    int a = 0;
    int b = 0;
    
    for ( i = 0; i < N; i++ ) {
        for ( j = i + 1; j < N; j++ ) {
            for ( a = 0; a < N - 1; a++ ) {
                for ( b = a + 1; b < N; b++ ) {
                    if ( in[i] == in [j] ) {
                        if ( in[i] == out[b] && in[j] == out[a] ) {
                            return -1;
                        }
                    }
                }
            }
        }
    }
    return 0;
}
