#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int Partition(int *A, char *C, int f, int l){
  int i, j, x;
  char c;
  i = f-1;
  for(j = f; j < l; j++){
    if(A[j] <= A[l]){
      i = i+1;
      x = A[j];
      A[j] = A[i];
      A[i] = x;

      c = C[j];
      C[j] = C[i];
      C[i] = c;
    }
  }
    x = A[i+1];
    A[i+1] = A[l];
    A[l] = x;

    c = C[i+1];
    C[i+1] = C[l];
    C[l] = c;

  return i+1;
}

void Quicksort(int *A, char *C, int f, int l){
  int q;
  if(f < l){
    q = Partition(A,C,f,l);
    Quicksort(A,C,f,q-1);
    Quicksort(A,C,q+1,l);
  }
}

void Countingsort(int *A, char *B, char *D, int n){
  int i, j, k=10000000001, C[k];
  for(i = 0; i <= k; i++) C[i] = 0;
  for(j = 0; j < n; j++) C[A[j]]++;
  for(i = 0; i <= k; i++) C[i+1] = C[i] + C[i+1];
  for(j = n-1; j >= 0; j--){
    B[C[A[j]]-1] = D[j];
    C[A[j]]--;
  }
}
int main(){
  int i, n, m, *A;
  char *B, *C, *D;
  scanf("%d",&n);
  A = malloc(sizeof(int)*n);
  B = malloc(sizeof(char)*n);
  C = malloc(sizeof(char)*n);
  D = malloc(sizeof(char)*n);
  for(i = 0; i < n; i++){
    scanf(" %c%d",&C[i], &A[i]);
  }
  strcpy(D,C);

  Countingsort(A,B,D,n);
  Quicksort(A,C,0,n-1);

  if(strcmp(C,B) == 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}