#include <stdio.h>
#define MAX 100000
#define MAX2 1000
 
int partition( int *A, int *Order, int p, int r );
 
int Quicksort( int *A, int *Order, int p, int r );

int IsStable(int Arr[MAX], int Order[MAX], int num );

int Store(int Arr[MAX], int Order[MAX], int Storage[MAX2][MAX2], int num );

int Judge_Include(int Storage[MAX2][MAX2], int num_for_store, int a);

void Insert(int Arr[MAX], int Order[MAX], int i, int Storage[MAX2][MAX2], int num_for_Store, int num ) ;


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);
    for ( i = 0; i < order; i++ ) {
        Arr2[i] = Arr[Order[i]];
    }

    flag = IsStable( Original, 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 IsStable(int Arr[MAX], int Order[MAX], int num ) 
{
	int i = 0;
	int a = 0;
	int b = 0;
	int Storage[MAX2][MAX2] = {};
	int num_for_store = 0;
	
	for ( a = 0; a < MAX2; a++ ) {
	    for ( b = 0; b < MAX2; b++ ) {
	        Storage[a][b] = -1;
	    }
	}
	
	num_for_store = Store(Arr, Order, Storage, num);
	
	
	for ( i = 0; i < num_for_store; i++ ) {
		for ( a = 0; Storage[i][a] >= 0; a++ ) {
			for ( b = a + 1; Storage[i][b] >= 0; b++ ) {
				if ( Order[Storage[i][a]] > Order[Storage[i][b]] ) {
					return -1;
				}
			}
		}
	}
	
	return 0;
}

int Store(int Arr[MAX], int Order[MAX], int Storage[MAX2][MAX2], int num )
{
	int i = 0;
	int j = 0;
	int a = 0;
	int b = 0;
	int num_for_store = 0;
	
	for ( i = 0; i < num; i++ ) {
		if ( Judge_Include(Storage, num_for_store, i) < 0 ) {
			continue;
		}
		
		for ( j = i+1; j < num; j++ ) {
			if ( Judge_Include(Storage, num_for_store, j) < 0 ) {
				continue;
			}
			
			if ( Arr[Order[i]] != Arr[Order[j]] ) {
				continue;
			}
			
			Insert(Arr, Order, i, Storage, num_for_store ,num);
			num_for_store++;
		}
	}
	
	return num_for_store;
}

int Judge_Include(int Storage[MAX2][MAX2], int num_for_store, int a)
{
	int i = 0;
	int j = 0;
	
	for ( i = 0; i < num_for_store; i++ ) {
		for ( j = 0; Storage[i][j] >= 0; j++ ) {
			if ( Storage[i][j] == a ) {
				return -1;
			}
		}
	}
	
	return 0;
}

void Insert(int Arr[MAX], int Order[MAX], int i, int Storage[MAX2][MAX2], int num_for_store, int num ) 
{
	int j = 0;
	int k = 0;
	
	for ( j = 0; j < num; j++ ) {
		if ( Arr[Order[j]] == Arr[Order[i]] ) {
			Storage[num_for_store][k] = j;
			k++;
		}
	}
}
