#include <stdio.h>
#include <stdbool.h>

#define MAXSIZE 100000

struct card{
    char suit[1]; //S, H, C, D
    int value; //1,2,..,9
};

void trace(struct card A[], int N){
    for(int i = 0; i < N; i++){
        printf("%c %d\n", *A[i].suit, A[i].value);
    }
}

bool isStable(struct card A[], struct card B[], int N){
    for(int i = 0; i < N; i++){
        if(*B[i].suit != *A[i].suit) return false;
    }
    return true;
}

void BubbleSort(struct card B[], int N){
    int i,j,t1;
    char t2[1];
    for(i = 0; i < N; i++){
        for(j = N-1; j > i; j--){
            if( B[j].value < B[j-1].value){
                t1 = B[j].value;
                *t2 = *B[j].suit;
                B[j].value = B[j-1].value;
                *B[j].suit = *B[j-1].suit;
                B[j-1].value = t1;
                *B[j-1].suit = *t2;
            } 
            
        }

    }
}

int Partition(struct card A[], int p, int r){
    int x = A[r].value;
    int i = p - 1;
    int j, t1;
    char t2[1];

    for(j = p; j < r; j++){
        if(A[j].value <= x){
            i++;
            t1 = A[i].value;
            A[i].value = A[j].value;
            A[j].value = t1;
            *t2 = *A[i].suit;
            *A[i].suit = *A[j].suit;
            *A[j].suit = *t2;
        }

    }
    

    t1 = A[i + 1].value;
    A[i + 1].value = A[r].value;
    A[r].value = t1;
    *t2 = *A[i + 1].suit;
    *A[i + 1].suit = *A[r].suit;
    *A[r].suit = *t2;

    return i + 1;

}


void Quicksort(struct card A[], int p, int r){
    int q;
    if(p < r){
        q = Partition(A, p, r);
        Quicksort(A, p, q - 1);
        Quicksort(A, q + 1, r);
    }
}


int main(){
    int i, N;
    struct card A[MAXSIZE], B[MAXSIZE];

    scanf("%d", &N);
    for(i = 0; i < N; i++){
        scanf("%s %d", A[i].suit, &A[i].value);
    }
    for( i = 0; i < N; i++ ){
        *B[i].suit = *A[i].suit;
        B[i].value = A[i].value;
    }

    Quicksort(A, 0, N - 1);
    BubbleSort(B, N);

    if(isStable(A, B, N)){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    trace(A, N);
    // trace(B, N);

    return 0;
}
