#include<stdio.h>
#define MAX 100000
#define TRUE 1
#define FALSE 0
typedef struct{
    char mark;
    int num;
}trump;
int partition(trump *, int, int);
void quicksort(trump *, int, int);
int isStable(trump *, trump *, int);

int main(){
    int i,n;
    trump card[MAX],data[MAX];
    
    scanf("%d",&n);
    for(i=0; i<n; i++){
        
        scanf("%c %d",&card[i].mark,&card[i].num);
        data[i] = card[i];
    }
    
    quicksort(card, 0, n-1);
    if(isStable(data, card, n) == TRUE) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++){
        printf("%c %d\n",card[i].mark,card[i].num);
    }
    return 0;
}

int partition(trump *card, int p, int r){
    int i,j,x;
    trump temp;
    x = card[r].num;
    i = p-1;
    for(j=p; j<r; j++){
        if(card[j].num <= x){
            i = i+1;
            temp = card[i];
            card[i] = card[j];
            card[j] = temp;
            
        }
    }
    temp = card[i+1];
    card[i+1] = card[r];
    card[r] = temp;
   
    return i+1;
}

void quicksort(trump *card, int p, int r){
    int q;
    if(p<r){
        q = partition(card, p, r);
        quicksort(card, p, q-1);
        quicksort(card, q+1, r);
    }
}

int isStable(trump *data, trump *card, int n){
    int i,j,a,b;
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            for(a=0; a<n; a++){
                for(b=a+1; a<n; a++){
                    if(data[i].num == data[j].num && data[i].mark != card[a].mark && data[j].mark != card[b].mark){
                        return FALSE;
                    }
                    
                }
            }
        }
    }
    return TRUE;
}




