#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(0, n-1);
    
    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, v;
  char c;
     
    x = A[r].value;
    i = p - 1;
     
    for(j = p; j < r; j++){
        if(A[j].value <= x){
            i = i + 1;
     v = A[i].value;
     A[i].value = A[j].value;
     A[j].value = v;
     c = A[i].gara;
     A[i].gara = A[j].gara;
     A[j].gara = c;

        }
    }
     v = A[i+1].value;
     A[i+1].value = A[r].value;
     A[r].value = v;
     c = A[i+1].gara;
     A[i+1].gara = A[r].gara;
     A[r].gara = c;
     
    return i+1;
     
}