#include<stdio.h>

#define N 100000

typedef struct{
    char gara;
    int value;
} card;

void Quicksort(int, int);
int Partition(int, int);

card A[N];

int main(){
    int n, i, s = 0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++)  scanf(" %c%d", &A[i].gara, &A[i].value);
    
    Quicksort(1, n);
    
    for(i = 0; i < n; i++){
        if(A[i].value == A[i+1].value && A[i].gara > A[i+1].gara) s++;
        }
    
    if(s != 0) printf("Stable\n");
    else printf("Not stable\n");
  
    for(i = 0; i < n; i++) printf("%c %d\n", A[i].gara, A[i].value);
    
    return 0;
    
}

void Quicksort(int p, int r){
    int q;
    
    if(p < r){
        q = Partition(p, r);
        Quicksort(p, q - 1);
        Quicksort(q + 1, r);
    }
}

int Partition(int p, int r){
    int i, j, x;
    card y;
    
    x = A[r].value;
    i = p - 1;
    
    for(j = p; j < r-1; j++){
        if(A[j].value <= x){
            i = i + 1;
            y = A[i];
            A[i] = A[j];
            A[j] = y;
        }
    }
    
    y = A[i+1];
    A[i+i] = A[r];
    A[r] = y;
    
    return i+1;
    
}