#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 Judge_stable ( int *Arr, int *Order, int Max_order );

int main(void)
{
    int Arr[MAX] = {};
    int Original[MAX] = {};
    int Order[MAX] = {};
    int Arr2[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 = Judge_stable ( Arr, Order, order );
    if ( flag > 0 ) {
        printf("Not stable\n");
    } else {
        printf("Stable\n");
    }
    
    for ( i = 0; i < order - 1 ; i++ ) {
        printf("%c %d\n", str[Order[i]][0], Arr[Order[i]]);
    }
    printf("%c %d\n", str[Order[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 Judge_stable ( int *Arr, int *Order, int Max_order )
{
	/* 宣言 */
    int number_for_comp = 1;						/* 値があるかどうかを確認するためのもの */
    int indexes_of_the_same_value[10][5] ={};		/* 同じ値になる添え字を入れる配列	 	*/
    int count_of_indexes = 0;						/* 同じ値をとる添え字の個数を数える		*/
    int i = 0;										/* ループ								*/
    int j = 0;										/* ループ								*/
    int k = 0;										/* ループ								*/
    int target_index[4] = {};						/* 比較のために添え字を入れておくところ */
    int stable = 0;									/* 安定確認フラグ						*/
    
    /* 元のデータから同じ値をとる添え字を格納する */
    for ( number_for_comp = 1; number_for_comp < 10; number_for_comp++ ) {
        
    	/* 同じ値をとる添え字の個数の初期化 */
    	count_of_indexes = 0;
    	
    	/* 添え字を格納する */
    	for ( i = 0; i < Max_order; i++ ) {
            if ( Arr[i] == number_for_comp) {
                indexes_of_the_same_value[number_for_comp][count_of_indexes] = i;
                count_of_indexes++;
            }
        }
    	/* 同じ値をとる添え字の個数を格納する */
        indexes_of_the_same_value[number_for_comp][4] = count_of_indexes;
    }
	
    /* 同じ値の添え字が入れ替わったのかを確認する */
	stable = 0;
	for ( number_for_comp = 1; number_for_comp < 10; number_for_comp++ ) {
		/* 添え字の個数を見てループすべきなのかを判定しcontinueを実行する */
        if ( indexes_of_the_same_value[number_for_comp][4] < 2 ) {
            continue;
        }
        
        /* 判断に使う添え字をそろえる */
        k = 0;
        for ( j = 0; j < indexes_of_the_same_value[number_for_comp][4]; j++ ) {
            for ( i = 0; i < Max_order; i++ ) {
                if ( Order[i] == indexes_of_the_same_value[number_for_comp][j] ) {
                    target_index[k] = i;
                    k++;
                }
            }
        }
        
        /* 添え字が入れ替わったのかを判断する */
        for ( k = 0; k < indexes_of_the_same_value[number_for_comp][4]; k++ ) {
            for ( j = k+1; j < indexes_of_the_same_value[number_for_comp][4]; j++ ) {
                if ( target_index[k] > target_index[j] ) {
                    stable = 1;
                    break;
                }
            }
            if (stable == 1) {
                break;
            }
        }
        if (stable == 1) {
            break;
        }
        
    }
    return stable;
}
